Compute Total Size of a File System

Asked at Google · Coding Questions · Difficulty: Easy · Last asked May 31, 2026

A file system is a tree: a directory holds files and other directories, and each file has a size in bytes. Given the root node of such a tree, return the total size of all files below it. Write it twice: once in any style you like, and once without recursion so that it also works on very deep trees.

Loading the problem…