Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Implement an in-memory file system
Implement an In-Memory File System
Implement an in-memory file system that supports fundamental directory and file operations. The system should not persist any data to disk.
Required Operations
ls(path)- If
pathrefers to a file, return a list containing only its name. - If
pathrefers to a directory, return the names of all files and subdirectories directly within it, sorted lexicographically.
- If
mkdir(path)- Create a new directory at the specified absolute path.
- Automatically create any necessary intermediate directories if they do not already exist.
addContentToFile(filePath, content)- If the file specified by
filePathdoes not exist, create it. - Append the provided
contentstring to the file's existing content.
- If the file specified by
readContentFromFile(filePath)- Return the complete content of the file specified by
filePath.
- Return the complete content of the file specified by
Constraints and Assumptions
- All paths provided are absolute and use
/as the separator. - The root directory is represented by
/. - Directory and file names will consist solely of lowercase letters.
- The system is entirely in-memory; no persistence is required.
- Operations should aim for reasonable time complexity.
AI interview prep
Core dilemma
Efficiently representing and navigating a hierarchical file system structure in memory, balancing path resolution speed with storage overhead and the complexity of managing file/directory metadata and content.
Mid-level signals3
Senior signals3
Red flags4
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement an in-memory file system
Implement an In-Memory File System
Implement an in-memory file system that supports fundamental directory and file operations. The system should not persist any data to disk.
Required Operations
ls(path)- If
pathrefers to a file, return a list containing only its name. - If
pathrefers to a directory, return the names of all files and subdirectories directly within it, sorted lexicographically.
- If
mkdir(path)- Create a new directory at the specified absolute path.
- Automatically create any necessary intermediate directories if they do not already exist.
addContentToFile(filePath, content)- If the file specified by
filePathdoes not exist, create it. - Append the provided
contentstring to the file's existing content.
- If the file specified by
readContentFromFile(filePath)- Return the complete content of the file specified by
filePath.
- Return the complete content of the file specified by
Constraints and Assumptions
- All paths provided are absolute and use
/as the separator. - The root directory is represented by
/. - Directory and file names will consist solely of lowercase letters.
- The system is entirely in-memory; no persistence is required.
- Operations should aim for reasonable time complexity.