This question evaluates a candidate's ability to design and implement in-memory file system data structures and APIs, covering hierarchical directory modeling, path parsing, file content management, and efficient mutable state handling.
Implement an in-memory file system supporting basic directory and file operations.
You must support the following methods (names are illustrative; any equivalent interface is fine):
ls(path)
path
is a file path, return a list containing
only the file name
.
path
is a directory path, return the names of
files and subdirectories directly under it
, sorted lexicographically.
mkdir(path)
addContentToFile(filePath, content)
content
to the existing file content.
readContentFromFile(filePath)
/
as the separator.
/
.