Question bank › Recursion
Dsa Recursion Medium

Recursive Directory Size Calculator

You are tasked with simulating a file system where each directory can contain files and other directories. Given a dictionary structure representing the file system, compute the total size of files within a specified directory, including all files in its subdirectories. Input: A dictionary where keys are directory names and values are either file sizes (int) or nested directories (also dictionaries). The input is read as a single line JSON string, where the root directory should be specified. Output: Print the total size of the files found in the specified directory and all its subdirectories. Example: Input: {"root": {"file1": 100, "file2": 200, "subdir": {"file3": 300}}} Output: 600

Key concepts

recursionfilesystemsdata structures

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.