Return all file paths via DFS
Company: NVIDIA
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of tree traversal and depth-first search along with competence in handling hierarchical data structures and constructing full file paths.
Constraints
- The total number of nodes is between 0 and 100000.
- Each file node has an empty `children` list.
- Node names are non-empty strings; the root name may be `/` or any directory name such as `root`.
Examples
Input: {'name': 'root', 'isFile': False, 'children': [{'name': 'a', 'isFile': False, 'children': [{'name': 'b.txt', 'isFile': True, 'children': []}, {'name': 'c', 'isFile': False, 'children': [{'name': 'd.md', 'isFile': True, 'children': []}]}]}, {'name': 'e.log', 'isFile': True, 'children': []}]}
Expected Output: ['root/a/b.txt', 'root/a/c/d.md', 'root/e.log']
Explanation: DFS visits `a` before `e.log`, then `b.txt`, then `c/d.md`, so the file paths are returned in that order.
Input: None
Expected Output: []
Explanation: An empty file system has no file paths.