In-Memory File System
Asked at Netflix· Onsite
Reported by the problem's creator, not verified
Build a file system that keeps directories and files in memory. Paths are absolute strings starting with / and split on /; / itself is the root directory. Each name between slashes contains only lowercase letters, digits and .. A path never passes through a file, and a name is never used as both a file and a directory.
Each test creates one FileSystem instance and runs a sequence of [method, [args]] calls. The output lists every call's return value, with None rendered as null.
Examples
Example 1
Input: init =
[], operations =[["mkdir",["/a/b"]],["add_content",["/a/b/c.txt","hello"]],["add_content",["/a/b/c.txt"," world"]],["read_content",["/a/b/c.txt"]],["ls",["/a"]],["ls",["/a/b"]],["ls",["/a/b/c.txt"]],["ls",["/"]]]Output:
[null,null,null,"hello world",["b"],["c.txt"],["c.txt"],["a"]]Explanation:
mkdir("/a/b")also creates the missing parent/a. The file receiveshelloand thenworld, so reading it returnshello world. Listing a file returns just that file's name.