In-Memory File System

Asked at Netflix· Onsite

Reported by the problem's creator, not verified

Import another question

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

  1. 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 receives hello and then world, so reading it returns hello world. Listing a file returns just that file's name.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.