AO
Back

File System Implementation

CodingOnsiteLast reported June 2026Medium Frequency

Problem Overview

The round is one problem built up across four parts, asked on both the phone screen and the onsite from the same bank, and known in the reports as "the vault question." Seven reports call it the easiest problem Harvey asks. One candidate finished every part in 45 minutes. The interviewer writes and runs their own test cases as you go, and does not always announce the rule a test is checking.

Implement an in-memory hierarchical file store. The original report's own description of the structure: "just a dict of dicts, passed down one level at a time."

Given — the API as the original report states it

class FileSystem:
    def add_file(self, path: str, content: str | None = None) -> str:
        """Store a file at 'path/to/somewhere/file.txt', creating missing folders."""
    def add_folder(self, path: str) -> str:
        """Create a folder, creating missing parents."""
    def get_file(self, path: str):
        """What lives at path: get_file('path/to/somewhere') -> file.txt,
        get_file('path/to') -> the folder 'somewhere'. Raise if nothing is there."""

Part 1 — add_file(), add_folder(), get_file()

  • Adding a file creates every missing intermediate folder.
  • Reading a folder path returns what is in it. One report frames this part as "create file or folder, and list the files under a folder."
  • Candidates finish this quickly. The interviewer starts running tests immediately.

Part 2 — at most 5 entries per directory

  • Files and folders share one namespace per level. Once a directory holds 5 entries, nothing more can be added under it.
  • The trap: a longer new path counts too. Creating a new intermediate folder inside a full directory is rejected, in the original report's words, "not even a new path is allowed."

Part 3 — duplicate names

  • A name that already exists at its level is renamed the way a desktop does: file.txt, file(1).txt, file(2).txt.
  • The interviewer's own test: add file.txt, file.txt, then file(1).txt. The third must become file(1)(1).txt, not file(2).txt. The counter wraps the whole current name.
  • One report uses a space, a (1).txt. Ask which form the interviewer wants before coding.
fs.add_file("file.txt")      # file.txt
fs.add_file("file.txt")      # file(1).txt
fs.add_file("file(1).txt")   # file(1)(1).txt

Part 4 — two questions, no code

  • How do you tell whether two files have the same content when their names, paths, and timestamps differ? A candidate who answered with a content hash, SHA-256 or MD5, passed and got the onsite.
  • How would this run in production? The original poster found the question unfocused. Have a concrete answer ready: bytes in blob storage, the path-to-blob mapping and the folder tree in a database.

The reported wall — not the code. Because the problem is easy, the round is decided on the follow-ups, the live tests, and how you hold up under pushback. The original report's interviewer challenged the approach several times before the tests ran and then conceded. One candidate solved every part with a trie and was rejected without explanation. Solve it cleanly, ask about the rename rule up front, and keep your composure.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Edge cases · 1Trade-off discussion · 3
Edge cases

How would you handle duplicate file names in the same directory?

Probes for: After basic implementation is working
Trade-off discussion

Add a constraint: each directory can hold at most 5 items (files and folders combined). How do you enforce this?

Probes for: After duplicate handling is discussed

How would you determine if two files have identical content?

Probes for: After core implementation

How would you implement this file system in a production environment?

Probes for: After coding discussion, production context

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Flat HashMap with full-path keysSimpler to implement for basic add/get; avoids building a tree. However, listing directory contents or enforcing per-directory constraints (max 5 items) requires scanning all keys with a given prefix, which is less efficient and harder to maintain.
Trie (explicit tree nodes)Naturally models the hierarchy; makes listing children and enforcing per-level constraints straightforward. Slightly more complex to implement than a flat map but scales better for deep path queries and listing operations.

What Reports Emphasize

Common mistakes: Not anticipating the tricky duplicate-name test case where the counter wraps the whole filename — e.g., treating file(1).txt as already-taken and not producing file(1)(1).txt.; Candidates who failed did not know what the production follow-up was asking and gave unfocused answers about storage structures and NoSQL without a clear direction.; One candidate completed every coding part correctly but was inexplicably rejected due to a disengaged interviewer, suggesting non-technical factors can also sink outcomes.

Interviewer hints: The interviewer ran specific test cases without announcing them in advance, including the three-add duplicate collision case, then asked 'do you know what these test cases are doing?'; One interviewer explicitly said the tricky part is handling duplicate file names — A becomes A(1) on re-insert.; The production follow-up ('how would you implement this in production?') was asked verbally without requiring code; the interviewer seemed to want a high-level architectural answer but was not clear about what specifically they wanted.

What passers do: Candidates who prepared from prior reports and knew the duplicate-filename test case (add(file.txt), add(file.txt), add(file(1).txt) → file.txt, file(1).txt, file(1)(1).txt) handled it quickly and correctly.; Using a Trie (prefix tree) structure was specifically mentioned as a clean way to implement the directory hierarchy; candidates who used it moved through the problem fast.; Answering the 'identical file content' follow-up with file hashing (SHA-256 / MD5) led to passing the phone screen.; Finishing the core coding quickly (one candidate finished all parts in 45 minutes) left time for discussion rather than pressure.

Practice

Write your own against 8 test cases, or read the worked solution — approach, complexity, and code that runs.
Harvey AI · Coding · Reported 7× across candidate reports
Is this helpful?