Design an In-Memory Unix File System
Last updated: September 4, 2025
Quick Overview
Implement a class with mkdir, ls, addContentToFile, and readContentFromFile methods. Tests OOP design, trie/hashmap usage, and edge case handling.
Perplexity
September 4, 202512
9
4,750 solved
Implement a class with mkdir, ls, addContentToFile, and readContentFromFile methods. Tests OOP design, trie/hashmap usage, and edge case handling.
Reported directly by Perplexity candidates. Tests practical OOP design and data structure selection for hierarchical data.
What the Interviewer Expects
- Design a clean class interface with proper method signatures
- Use a trie or nested dictionary for path representation
- Handle edge cases: root directory, empty paths, non-existent paths
- Support both files and directories at the same path level
- Write clean, readable Python code
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you add support for deleting files?
- How would you implement file permissions?
- What data structure would you use for efficient ls on large directories?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem requires designing an in-memory Unix file system, which involves managing directories and files using a structured approach. A trie (prefix tree) is a suitable data structure for this prob...
Approach
-
Define a TrieNode class: Each node has a dictionary for children (representing directories and files), a boolean to indicate if it's a file, and a content string for file content.
-
**Impleme...