AO
Back

File System Implementation

CodingPhone, OnsiteLast reported June 2026Medium Frequency

Problem Overview

The round: one problem built up in three parts, reported in four phone screens and four onsites between May 2025 and June 2026 (a ninth report does not say which round). The original report, a phone screen, describes an interviewer who wrote and ran his own test cases without saying which rule each one checked, and questioned the candidate's test results several times before conceding he had made the mistake himself. Another early candidate says the question was so new that the interviewer worked out the requirements from his own test data during the call. One onsite candidate called it very simple and finished in 45 minutes; a reply under that report guesses it is the easiest in Harvey's bank. Outcomes vary: passers and rejections both appear, and two candidates who solved every part were still turned down.

What the reports give. The original report names two operations, addFile(String path) and getFile(String path): adding "path/to/somewhere/file.txt" stores the file, getFile("path/to/somewhere") returns file.txt, and getFile("path/to") returns the folder somewhere. A later onsite report describes the same round as "create file/folder and list files under folder". Our setup — ask your interviewer: the Python names below, add_folder for "create folder", relative paths separated by "/", add_file creating any missing folders on its path (the original example only ever calls addFile, yet path/to then holds somewhere), and get_file on a folder returning the names in it.

class FileSystem:
    def __init__(self): ...
    def add_file(self, path: str): ...    # store a file; create missing folders on the way
    def add_folder(self, path: str): ...  # create a folder
    def get_file(self, path: str): ...    # a folder path -> the names in that folder

The tests compare each listing as a sorted list of names, so any collection in any order passes. They never check what add_file returns, and a refused add may raise, return False or print: the tests only check that the folder did not change.

Part 1 — Add files, list a folder

  • add_file(path) stores a file, creating every missing folder on its path.
  • add_folder(path) creates a folder. The tests create one folder inside a folder that already exists.
  • get_file(path) on a folder returns the names directly inside it, files and folders alike. An empty folder returns nothing.
fs = FileSystem()
fs.add_file("path/to/somewhere/file.txt")
fs.get_file("path/to/somewhere")   # file.txt
fs.get_file("path/to")             # somewhere

Part 2 — Five entries per folder

  • In the original report's words, each level holds at most 5 things, folders and files together; once a level has 5, no new folder or file can be added there, "not even a new path".
  • So with d holding 5 entries, both d/f5.txt and d/sub/deep.txt are refused, and a refused add leaves nothing behind (no half-created sub).
  • The limit is per folder: a full folder does not affect a different folder.
  • No report says whether a full folder also blocks adding inside one of its existing subfolders, which gains no new entry itself. Ask; the tests accept both answers (the reference lets the add through, our reading).

Part 3 — Duplicate names

  • A file whose name is already taken in its folder is renamed the way a desktop does: file.txt, file(1).txt, file(2).txt. The same name in a different folder is not a duplicate.
  • The interviewer's own test in the original report: add file.txt, add file.txt, then add file(1).txt. The three files are file.txt, file(1).txt and file(1)(1).txt.
  • The original report writes file(1).txt; one onsite report writes a (1).txt, with a space. Ask which; the tests accept both.
  • The Part 2 limit still applies.
fs.add_file("v/file.txt")      # v: file.txt
fs.add_file("v/file.txt")      # v: file.txt, file(1).txt
fs.add_file("v/file(1).txt")   # v: file.txt, file(1).txt, file(1)(1).txt

Follow-up Arc

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

Each folder can hold at most 5 entries, files and folders together, and a full folder refuses even a new path through it. How do you enforce this?

Probes for: After addFile and getFile work

If a file name already exists in its folder, rename the new file the way a desktop does: file.txt, file(1).txt, file(2).txt. What do file.txt, file.txt, then file(1).txt become?

Probes for: After the 5-entry limit

How do you tell whether two files have the same content when their metadata differs?

Probes for: Spoken, after the code

How would you run this in production?

Probes for: Spoken, after the code

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Flat HashMap with full-path keysA reply under the original report notes it is simpler if you never list a folder. Reading one file by full path is a single lookup, but listing a folder or counting its entries scans every key for the prefix.
Trie (explicit tree nodes)Models the hierarchy, so listing a folder and counting its entries are direct. One candidate used a trie, solved every part and was still rejected; no report ties the structure to the outcome.

What Reports Emphasize

Common mistakes: One candidate, who failed, could not tell what the production follow-up wanted; his answer about storage layout, NoSQL and keeping addresses in a database did not seem to land.; One candidate solved every part with a trie and was rejected without a reason; the candidate says the interviewer was busy with other work throughout.; Not reported, a code pitfall: numbering from a stripped base name turns file(1).txt into file(2).txt, where the interviewer's test expects file(1)(1).txt.

Interviewer hints: In the original report the interviewer ran his own test cases without saying which rule each checked, including file.txt, file.txt, then file(1).txt, and then asked whether the candidate knew what those tests were doing.; The same interviewer questioned the candidate's test results several times, then found the mistake was his own.; In an early report the question was so new that the interviewer worked out its requirements from his own test data during the call.; The same-content and production questions were asked with no code.

What passers do: One candidate prepared from an earlier report, answered the same-content follow-up with file hashing (SHA-256 or MD5), and passed the phone screen.; Another candidate passed the onsite; that report names the question and gives no other detail.

Practice

Write your own against 10 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Harvey AI with friends?

Send them this page. It is free to read, no account needed.

More Harvey AI Questions

Free preview

Every question in the Harvey AI catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 10 Harvey AI questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Harvey AI · Coding · Reported 9× across candidate reports
Is this helpful?