Largest File in a Long Listing
Problem statement
You receive lines from a conventional ls -l style listing. A file-entry line has eight whitespace-separated fields (permissions, link count, owner, group, byte size, month, day, time/year), followed by the filename as the remaining text. Return the filename of the largest regular file, identified by a permissions field starting with -.
Ignore total-summary lines, directories, and symbolic links. For equal sizes choose the ASCII lexicographically smallest filename. If there is no regular file, return an empty string. Filenames may contain internal spaces.
Function
largestFile(lines: String[]) → StringExamples
Example 1
lines = ["-rw-r--r-- 1 owner group 8 Jan 01 12:00 notes.txt","-rw-r--r-- 1 owner group 25 Jan 01 12:00 long name.txt"]return = "long name.txt"The second regular file has more bytes.
Example 2
lines = ["-rw-r--r-- 1 owner group 10 Jan 01 12:00 z.txt","-rw-r--r-- 1 owner group 10 Jan 01 12:00 a.txt"]return = "a.txt"Equal sizes use filename order.
Constraints
- For this exercise, assume at most 200000 lines and at most 2 million characters in total.
- Entry lines have the described eight fields; filenames are nonempty ASCII with no leading or trailing whitespace. Sizes are nonnegative and at most 10^12.