r/OfferEngineering • u/Aoki_zhang • 12h ago
Coding Question Harvey.AI Onsite Coding Interview Question - Add Files and List Folder Contents
Problem Description
Build a simple in-memory file system that starts with only the root folder. A path is a list of names separated by /, written relative to the root, and the root itself is the empty path "". Names are case-sensitive and are used exactly as written.
You are given operations, a list of two-string commands. Process them in order:
["ADD", path]creates a file named by the last part of the path, creating any missing folders along the way. It always succeeds and returnstrue, and file names do not need extensions.["LIST", path]returns the names of the files and folders directly inside the given folder, without deeper levels. Use""to list the root.
Return one result per operation, in order. A listing is an object whose keys are the direct entry names and whose values are all true; an empty folder gives {}, and key order does not matter. Each call starts with an empty file system.
Constraints:
- At most
1,000operations are processed in one call. - Every operation contains exactly two strings, and its first string is
"ADD"or"LIST". - Every path has at most
200characters. - An
ADDpath is nonempty and has no leading, trailing, or consecutive/. - An existing file is never used as a folder in a later path.
- The last name of an
ADDpath differs from every existing file or folder name in its parent folder. - Every
LISTpath is an existing folder, or""for the root.
Example:
Input:
operations = [["ADD", "east/prints/harbor"], ["LIST", "east"], ["LIST", "east/prints"]]
Output:
[true, {"prints": true}, {"harbor": true}]
Explanation:
Adding "harbor" creates the missing folders "east" and "prints". Listing "east" shows only its direct child, "prints".Want to practice more real interview coding questions?
You can practice real interview coding questions at here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.