FunctionRacerProblemsRace

Tiny Disk

HardClassesPython, JavaScript, TypeScript, Java, C++

Implement a class TinyDisk, a small file system. A path is / for the top folder, or names joined by slashes such as /notes/todo. A folder holds files and other folders, and a file holds text. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

TinyDisk()
write("/notes/todo", "milk") returns true
write("/notes/todo", "eggs") returns true
read("/notes/todo") returns "milkeggs"
make_folder("/notes/todo/x") returns false
make_folder("/pics") returns true
list_names("/") returns ["notes","pics"]
list_names("/notes/todo") returns ["todo"]
remove("/notes") returns 1
list_names("/") returns ["pics"]

The two writes create the folder notes and the file todo, which then reads milkeggs. A folder cannot be made below a file. The top folder lists notes and pics, and listing a file gives its own name. Removing notes deletes the one file inside it.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems