Google·Software Engineer·Onsite - Coding / Algorithms
- Given the root node of a file system where each node has a class, size, and contains field, compute the total size of all files in the tree.
- What is the time complexity of your traversal, and how would you speed up repeated size queries on the same directory?
- If a file is added or removed from the file system, how do you efficiently invalidate the cache?
- Can you rewrite your recursive DFS solution using an explicit stack instead?
“The base case is pretty clean, just a DFS summing sizes at file nodes.”