Nested Filesystem Size

Problem Model a filesystem of folders that contain files and sub-folders, and compute the total size of any node (the sum of all files beneath it). Solve it iteratively, then improve with a recursive traversal.

Input / Output

  • Input: a tree of folders and files, each file with a size; a starting node.
  • Output: the total size of all files under that node.

Constraints

  • Arbitrary nesting depth — discuss stack-depth limits for very deep trees.

Example

  • folder{ a.txt(10), sub{ b.txt(5) } } -> 15.
added …
LeaderboardSalaryAccount