FastPrepHierarchical In-Memory File System
Problems/Hierarchical In-Memory File System

Hierarchical In-Memory File System

Clay logoClay● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: Clay reports ask for a file-system data structure with files and folders, add/read/delete operations, plus a folder-tree variant with recursive creation, ordered listing, relocation, and deletion. This combined executable contract includes every recoverable operation and declares edge behavior; the judged core matches about 95%.

Process operations on an in-memory hierarchy rooted at /.

  • MKDIR path recursively creates missing folders and returns true, unless a path component is a file.
  • WRITE path content creates or replaces a file when its parent folder exists and returns whether it succeeded.
  • READ path returns file content or the empty string.
  • LIST path returns direct children sorted as comma-separated D:name or F:name.
  • MOVE source destinationFolder moves a file or folder under an existing folder, preserving its name. Reject root moves, cycles, and collisions.
  • DELETE path removes 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.

More Clay problems

  • Employee Count Median, Mean and ModePHONE SCREEN · Seen Nov 2026
  • Workspace File System With Folders and TablesPHONE SCREEN · Seen Sep 2026
  • Minesweeper Board UpdateONSITE INTERVIEW · Seen Apr 2025
See Clay hiring insights
Saved
class Solution {
    public String[] runHierarchicalFileSystem(String[][] operations) {
      // Write your code here.
    }

}
Checking account…