← HarveyAI Interview Insights

HarveyAI·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026Remote

Summary

HarveyAI coding round, got a file system design problem that looked deceptively clean until I started actually implementing it. Solid problem, probably worth grinding the path-parsing stuff before you go in.

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 went straight for a trie-style node structure where each node holds a name, a map of children, and a string for file content.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the file system as a tree of nodes, where each node represents either a directory or a file. Implement the operations by traversing the tree from the root, splitting paths by '/', and handling each component. Use a hash map to store children for efficient lookup, and store file content as a string.

Pro tip: Clarify assumptions upfront: whether paths are absolute, if directories can contain both files and subdirectories, and if content can be appended. This shows attention to detail and prevents misalignment with the interviewer.

1. Clarify requirements and edge cases

Ask about path format (absolute vs relative), whether mkdir should create intermediate directories, and if addContentToFile appends or overwrites. Confirm that ls returns sorted names and that paths are valid.

2. Design the data structure

Define a Node class with a name, a boolean isFile, a map of children (for directories), and a content string (for files). Use a root node representing '/'.

3. Implement path traversal helper

Create a method to split a path by '/' and traverse from the root, returning the target node or null if not found. This helper will be used by all operations.

4. Implement each operation

For mkdir, traverse to the parent and create a new directory node if it doesn't exist. For addContentToFile, traverse to the parent, create a file node if needed, and append content. For readContentFromFile, traverse to the file and return its content. For ls, traverse to the node and return sorted children names (or the file name if it's a file).

5. Analyze complexity and discuss trade-offs

Explain that each operation takes O(k) time where k is the number of path components, and space is O(total nodes). Discuss potential optimizations like using a trie or caching, and trade-offs between simplicity and performance.

Key Points to Mention

  • Tree data structure with nodes representing files and directories
  • Hash map for children to achieve O(1) average lookup per path component
  • Path splitting and traversal from root
  • Handling of edge cases: root path, non-existent paths, file vs directory
  • Time complexity: O(k) per operation where k is path depth
  • Space complexity: O(n) where n is total number of nodes

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