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)
-
If
path
is a file path, return a list containing
only the file name
.
-
If
path
is a directory path, return the names of
files and subdirectories directly under it
, sorted lexicographically.
-
mkdir(path)
-
Create a directory at the given absolute path.
-
Create any missing intermediate directories.
-
addContentToFile(filePath, content)
-
If the file does not exist, create it.
-
Append
content
to the existing file content.
-
readContentFromFile(filePath)
-
Return the full content of the file.
Notes / Constraints
-
Paths are absolute and use
/
as the separator.
-
The root directory is
/
.
-
Directory and file names consist of lowercase letters (you may assume no invalid characters).
-
The system is in-memory only (no persistence).
-
Aim for reasonable time complexity per operation.