Hierarchical In-Memory File System
Problem statement
Process operations on an in-memory hierarchy rooted at /.
MKDIR pathrecursively creates missing folders and returnstrue, unless a path component is a file.WRITE path contentcreates or replaces a file when its parent folder exists and returns whether it succeeded.READ pathreturns file content or the empty string.LIST pathreturns direct children sorted as comma-separatedD:nameorF:name.MOVE source destinationFoldermoves a file or folder under an existing folder, preserving its name. Reject root moves, cycles, and collisions.DELETE pathremoves a file or a folder and all descendants. Root cannot be deleted.
Return one string for every operation.
Function
runHierarchicalFileSystem(operations: String[][]) → String[]Examples
Example 1
operations = [["MKDIR","/a/b"],["WRITE","/a/b/note","hello"],["READ","/a/b/note"],["LIST","/a/b"],["DELETE","/a"],["READ","/a/b/note"]]return = ["true","true","hello","F:note","true",""]Recursive creation, file access, listing, and cascading deletion are applied in order.
Example 2
operations = [["MKDIR","/src/pkg"],["MKDIR","/dst"],["WRITE","/src/pkg/a","x"],["MOVE","/src/pkg","/dst"],["LIST","/dst"],["READ","/dst/pkg/a"]]return = ["true","true","true","true","D:pkg","x"]Moving a folder rewrites every descendant path.
Constraints
1 <= operations.length <= 10000- Paths are normalized absolute paths with no trailing slash except
/. - Names and file contents contain no commas.