← Harvey AI Interview Insights

Harvey AI·Software Engineer·Technical Phone Screen·Senior

SeniorPrefer not to say
Apr 2026Remote

Summary

Harvey AI coding round, one big design question that took the whole session. The problem looked like a toy filesystem at first but the constraints turned it into a mess of edge cases I was not fully prepared for.

Questions Asked (1)

Q1

Design and implement an in-memory hierarchical file system with addFile and get operations, a per-directory capacity limit of 5 entries, and OS-style auto-renaming for duplicate file names within the same directory.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

The rename logic is where I lost time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases (e.g., capacity enforcement, auto-renaming rules, path resolution). Then design a tree-based data structure with directories as nodes and files as leaves, and implement addFile and get operations with careful handling of duplicates and capacity limits. Discuss trade-offs and test with examples.

Pro tip: Mention that auto-renaming should follow OS conventions like appending ' (1)', ' (2)' before the extension, and handle cases where the renamed name also collides. Also, consider thread-safety if the system might be accessed concurrently.

1. Clarify Requirements and Edge Cases

Ask questions to understand expected behavior: What defines a duplicate? How should auto-renaming work (e.g., 'file.txt' -> 'file (1).txt')? What happens when a directory reaches capacity? Are paths absolute or relative? Should get return file content or metadata?

2. Design Data Structures

Propose a tree structure where each directory node contains a map of child names to entries (files or subdirectories) and a count of entries. Files can be represented as objects with name and content. Consider using a trie or nested hash maps for efficient lookup.

3. Implement Core Operations

Implement addFile(path, content): traverse/create directories, check capacity, handle duplicate names by auto-renaming, and insert the file. Implement get(path): traverse to the file and return its content, handling non-existent paths.

4. Handle Edge Cases and Constraints

Address capacity limit (reject if full), auto-renaming logic (find next available suffix), path normalization (e.g., trailing slashes, '..'), and potential concurrency issues if applicable.

5. Analyze Complexity and Trade-offs

Discuss time/space complexity: O(depth) for operations, O(n) for renaming in worst case. Compare alternatives like using a flat map with path keys vs. tree, and mention trade-offs in simplicity, performance, and memory.

Key Points to Mention

  • Tree-based data structure with directories as nodes and files as leaves, using hash maps for O(1) average child lookup.
  • Capacity enforcement: each directory tracks number of entries; addFile fails if limit reached.
  • Auto-renaming algorithm: split filename into base and extension, append ' (n)' incrementally until unique, respecting capacity.
  • Path resolution: handle absolute vs. relative paths, normalize paths, and traverse directory tree.
  • Error handling: return appropriate errors for full directories, invalid paths, or missing files.
  • Trade-offs: tree vs. flat map, recursive vs. iterative traversal, and potential concurrency considerations.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.