Design In-Memory File System
Design an in-memory file system to simulate ls, mkdir, addContentToFile, and readContentFromFile operations.

30:00

Design In-Memory File System
hard
Topics
Companies

Design an in-memory file system to simulate ls, mkdir, addContentToFile, and readContentFromFile operations.

Example 1:
Input: {"operations":["FileSystem","ls","mkdir","addContentToFile","ls","readContentFromFile"],"args":[[],["/"],["/a/b/c"],["/a/b/c/d","hello"],["/"],["/a/b/c/d"]]}
Output: [null,[],null,null,["a"],"hello"]
Constraints:
  • 1path.length,filePath.length1001 \leq \text{path.length}, \text{filePath.length} \leq 100

  • Path is a valid absolute path (starts with / and does not end with /, except for the root).

  • Directory and file names contain only lowercase English letters and digits.

  • At most 300300 calls in total to the four functions.

Input
arr ={"operations":["FileSystem","ls","mkdir","addContentToFile","ls","readContentFromFile"],"args":[[],["/"],["/a/b/c"],["/a/b/c/d","hello"],["/"],["/a/b/c/d"]]}

Operations: [FileSystem, ls, mkdir, addContentToFile, ls, readContentFromFile]

Operations

FileSystem

ls

mkdir

addContentToFile

ls

readContentFromFile

File System Tree

📁

/

(empty)

Variables
No variables to display
DepthFunction Call
Stack empty
0/1