As reported: Walmart Global Tech Staff Engineer (IN5) round 1 (Mar 2025), second question: design an in-memory file system — there is a root folder, each folder holds zero or more folders or text files, and you list all folders or files in a given folder.
Implement FileSystem:
ls(path)— ifpathis a file, a list with just the file name; if it is a folder, the names of its folders and files in lexicographic order.mkdir(path)— create the folder, including missing parents.addContentToFile(filePath, content)— create the file if needed (and parents), then appendcontent.readContentFromFile(filePath)— return the file's content.
The round's operation is listing a folder; the runner uses the full LeetCode version.
This is LeetCode 588 — Design In-Memory File System.
Example
["FileSystem","ls","mkdir","addContentToFile","ls","readContentFromFile"]
[[],["/"],["/a/b/c"],["/a/b/c/d","hello"],["/"],["/a/b/c/d"]]
-> [null,[],null,null,["a"],"hello"]
Constraints: paths are absolute, start with /, have no trailing / except the root, and use lowercase names; at most 300 calls.
Code runner format: two lines — the method names, then their arguments (LeetCode's format). Implement the FileSystem class; the harness prints the list of return values.