Coding questions · Intuit
Find largest filename from ls -l output
This question evaluates proficiency in text parsing, tokenization, and numeric comparison applied to command-line style output, emphasizing robust handling of varied input formats and edge cases.
You are given a multi-line string (via stdin) that represents the output of ls -l, with one entry per line.
Each file line follows the typical ls -l format:
<mode> <links> <owner> <group> <size> <month> <day> <time_or_year> <name...>
Task: print the file name (the <name...> part) of the entry with the largest <size>.
Requirements:
- Correctly parse columns so that you read the numeric
sizefield. - File names may contain spaces, so you cannot assume the name is a single token.
- Ignore non-entry lines such as
total Nif present.
Output only the file name of the largest file (any tie-breaking is acceptable unless otherwise specified).
Largest File Name from ls -l Output
Examples
Example 1
Input: ('total 8\n-rw-r--r-- 1 me staff 12 Jan 1 12:00 small.txt\n-rw-r--r-- 1 me staff 100 Jan 1 12:01 big file.txt',)
Output: 'big file.txt'
Explanation: File name contains spaces.
Example 2
Input: ('-rw-r--r-- 1 u g 5 May 1 2025 a\n-rw-r--r-- 1 u g 5 May 1 2025 b',)
Output: 'a'
Explanation: Tie keeps first.
Hints
- Choose a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.