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
Coding & Algorithms
Software Engineer
Perplexity
September 4, 2025
Software Engineer
Technical Phone Screen
Coding & Algorithms
Medium

12

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
Trie data structure
OOP design
File system modeling
Path parsing
Edge case handling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. 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.

  2. **Impleme...


Submit Your Answer
Markdown supported

Related Questions