I got this question in a codility test. Panicked and wasnt able to solve. Any ideas ?
You are given a string containing a detailed list of files. Your task is to evaluate a simple query on a certain subset of these files.
The string consists of N lines separated by end-of-line characters ( ASCII code 10). Each line contains information about one file, grouped in five columns: owner, perm, date, size and name(in that order). The columsns (except for the last one ) have fixed lengths and are separated by one space. They have the following meanings and format
-
Column perm has length 3 and contains info about permissions. It contains 3 characters: They control respectively whether reading, writing & execution of the file is permitted.The chars are respectively r, w & x if these operations are permitted; otherwise they are -.
-
Column owner has length 6 & contains a string representing the name of the user who created the file. The name is case sensitive and aligned to the left.
-
Colum size has a length of 10 & contains the size of the file in bytes. the size is less than 2^31 bytes and is aligned to the right.
-
Colum date has length 11 & contains the last modified date of the file in the format ''dd MMM YYYY''. The names of the months are Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov & Dec
-
Column name is of variable length and contains the name of the file. The name of the file consists of at most 255 printable ASCII chars and contains at least one dot character.
We are only interested in files that satisy:
- Files that are executable aka files with permission to execute
- They were created by the user admin
- Their size is less 14 * 2 ^ 20 bytes
Calculate the earliest last modification date of these files.
Write a function that given a strig describing the file list, returns the answer to the query, encoded as a string. Date should be returned in the format ''dd MMM yyyy'
If there are no such files return NO FILES
For example, given string S with N = 8 lines (enclosed between """):
"""
admin -wx 29 Sep 1983 833 source.h
admin r-x 23 Jun 2003 854016 blockbuster.mpeg
admin --x 02 Jul 1997 821 delete-this.py
admin -w- 15 Feb 1971 23522 library.dll
admin --x 15 May 1979 645922816 logs.zip
jane --x 04 Dec 2010 93184 old-photos.rar
jane -w- 08 Feb 1982 681574400 important.java
admin rwx 26 Dec 1952 14680064 to-do-list.txt
"""
The function should return "29 Sep 1983"
Assume that:
- N is an integer within the range [1 - 100]
- String s contains only of printable ASCII chars and EoL character
- String S is a correct list of files according to the specs above. Files can have the same names.