Print the File System State
Company: Anchorage
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to serialize and format in-memory data structures for deterministic textual output, focusing on representation of ordered collections and correct handling of empty versus non-empty blocks.
Constraints
- 0 <= number of blocks <= 10^4
- 0 <= number of records in each block <= 10^3
- The total number of records across all blocks is at most 10^5
- Each file record is a non-empty string containing only printable characters and does not contain commas or square brackets
Examples
Input: ([[], [], []],)
Expected Output: '[] -> [] -> []'
Explanation: There are three empty blocks, so each is printed as [] and connected with arrows.
Input: ([['a.txt'], [], ['b.txt', 'c.txt']],)
Expected Output: '[a.txt] -> [] -> [b.txt, c.txt]'
Explanation: The first block contains one file, the second block is empty, and the third block contains two files separated by a comma and space.
Input: ([],)
Expected Output: ''
Explanation: There are no blocks in the file system, so the formatted state is an empty string.
Input: ([['root', 'config'], ['log']],)
Expected Output: '[root, config] -> [log]'
Explanation: Both blocks are non-empty and are printed in order without a trailing arrow.
Input: ([['file1']],)
Expected Output: '[file1]'
Explanation: A single non-empty block is printed by itself with no arrow.
Hints
- Format each block independently first, then combine the block strings.
- Use string joining instead of repeatedly concatenating in a loop for better efficiency.