Search
⌘K
Get Premium
Early Access
Common Problems
File System
Understanding the Problem
📁 What is an In-Memory File System?
You already know what a file system is, you use one every day. Open Finder or Windows Explorer, and you're navigating folders, creating files, moving things around. An in-memory file system is just that, minus the disk. Everything lives in RAM, which means we get to focus purely on the data structures and operations without worrying about persistence, caching, or I/O performance.
Requirements
When the interview starts, you'll get something like:
"Design an in-memory file system that supports creating files and directories, navigating paths, and basic file operations."
File systems are familiar territory, which makes this problem deceptively tricky. Everyone knows how file systems work from using their computer, so candidates often skip clarification and start designing immediately. That's a mistake. The interviewer has specific expectations about scope, and your mental model of "file system" might not match theirs.
Clarifying Questions
Structure your questions around what the system does, what the structure looks like, and what's explicitly out of scope.
Here's how the conversation might go:
You: "For the hierarchy, are we dealing with a single root like Unix, or multiple roots like Windows drive letters?"Interviewer: "Single root. Keep it Unix-style with paths like /home/user/file.txt."
That simplifies path resolution significantly.
You: "What operations do we need to support? I'm thinking create, delete, list contents. Anything else?"Interviewer: "Those plus move and rename. You should also be able to navigate to any path and get its contents."
You: "For files specifically, do they store actual content, or are they just names in the tree?"Interviewer: "They should store content. Simple string content is fine."
You: "What about error cases? If someone tries to create a file at a path where the parent folder doesn't exist, or tries to delete the root?"Interviewer: "Those should throw exceptions. Use specific exception types so callers can handle different failure modes appropriately."
You: "What scale are we targeting? Dozens of files, or potentially thousands?"Interviewer: "Assume tens of thousands of entries. It should stay responsive even with deep folder hierarchies."
Worth knowing. This will influence data structure choices later.
You: "Last question. What's out of scope? Permissions, timestamps, symbolic links?"Interviewer: "All out of scope. Focus on the core tree structure and operations."
Final Requirements
After that back-and-forth, you'd write this on the whiteboard:
Final Requirements
Requirements:
1. Hierarchical file system with single root directory
2. Files store string content
3. Folders contain files and other folders
4. Create and delete files and folders
5. List contents of a folder
6. Navigate/resolve absolute paths (e.g., /home/user/docs)
7. Rename and move files and folders
8. Retrieve full path from any file/folder reference
9. Scale to tens of thousands of entries in memory
Out of Scope:
- Search functionality
- Relative path resolution (../ or ./)
- Permissions, ownership, timestamps
- File type-specific behavior
- Persistence / disk storage
- Symbolic links
- UI layerWe've scoped the problem tightly. Now we know exactly what to build.
Core Entities and Relationships
With requirements clear, we need to identify the objects that make up this system.
Class Design
FileSystem
File
Folder
Shared Abstraction: FileSystemEntry
Final Class Design
Implementation
FileSystem
The Path Resolution Helpers
FileSystemEntry
Folder
File
Complete Code Implementation
Verification
Extensibility
"How would you make this file system thread-safe?"
"How would you add search functionality?"
What is Expected at Each Level?
Junior
Mid-level
Senior
Purchase Premium to Keep Reading
Unlock this article and so much more with Hello Interview Premium
Currently up to 25% off
Hello Interview Premium
Reading Progress
On This Page
Understanding the Problem
Requirements
Clarifying Questions
Final Requirements
Core Entities and Relationships
Class Design
FileSystem
File
Folder
Shared Abstraction: FileSystemEntry
Final Class Design
Implementation
FileSystem
FileSystemEntry
Folder
File
Complete Code Implementation
Verification
Extensibility
"How would you make this file system thread-safe?"
"How would you add search functionality?"
What is Expected at Each Level?
Junior
Mid-level
Senior

Schedule a mock interview
Meet with a FAANG senior+ engineer or manager and learn exactly what it takes to get the job.