Largest File in a Long Listing
Updated
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.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Count Proper Prefix MatchesAT&T · OAAT&T interview questions
- Decode Words with Anagram KeysCresta · OACresta interview questions
- String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
- Longest String ChainVisa · OAVisa interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Return Exact Cash Register ChangeBank of America · OA
- Largest Binary Number by ConcatenationAdobe · OAAdobe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA
- Frequently Bought TogetherAmazon · OA
- Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions