← Harvey Interview Insights

Harvey·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Coding round at HarveyAI where the whole problem was building an in-memory file system from scratch. Pretty classic LC-style problem but the edge cases in path parsing tripped me up more than I expected.

Questions Asked (1)

Q1

Design and implement an in-memory file system that supports ls(path), mkdir(path), addContentToFile(path, content), and readContentFromFile(path).

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I jumped straight into coding the trie node structure without talking through the design first, which I regret.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases (e.g., path formats, file vs directory, content updates). Then propose a tree-based design using a node class with children map and content string, and implement each operation with path traversal. Discuss trade-offs and potential optimizations.

Pro tip: Mention that using a trie-like structure with hash maps for children ensures O(1) average lookup per path component, and that storing content only in file nodes simplifies logic. Also, proactively discuss handling of absolute vs relative paths and error conditions.

1. Clarify requirements and assumptions

Ask about path format (absolute vs relative), whether paths always start with '/', and expected behavior for invalid operations (e.g., creating a directory that already exists).

2. Design data structures

Propose a Node class with a map of child nodes (name -> Node) and a content string (empty for directories). Use a root node representing '/'.

3. Implement path traversal

Write a helper to split the path by '/' and traverse from root, creating intermediate directories for mkdir and addContentToFile as needed.

4. Implement each operation

For ls, return sorted child names if directory, or [filename] if file. For mkdir, create directories recursively. For addContentToFile, create file if not exists and append content. For readContentFromFile, return content if file exists.

5. Analyze complexity and trade-offs

Discuss time complexity O(k) where k is number of path components, and space O(total nodes). Mention alternative designs like using a single map with full paths and their trade-offs.

Key Points to Mention

  • Tree structure with nodes representing files and directories
  • Using hash maps for O(1) child lookup
  • Path splitting and traversal logic
  • Handling of edge cases: root path, non-existent paths, file vs directory conflicts
  • Time and space complexity analysis
  • Potential optimizations: caching, lazy deletion, or using a trie

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