← HarveyAI Interview Insights

HarveyAI·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Interviewed for a software engineering role at HarveyAI and got a spreadsheet-style coding problem involving circular dependency detection. Pretty niche problem if you haven't thought about graph cycles in a while.

Questions Asked (1)

Q1

Implement a spreadsheet cell system where setting a cell's value can detect circular dependencies.

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

The core of it is cycle detection in a directed graph, which sounds clean until you're mid-implementation and realize you need to track not just current deps but transitive ones too.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the spreadsheet as a directed graph where cells are nodes and dependencies are edges. When setting a cell's value, perform a depth-first search (DFS) from that cell to detect cycles; if a cycle is found, reject the update. Otherwise, update the cell and propagate changes to dependents.

Pro tip: Discuss how to handle dynamic updates efficiently, such as using topological sorting or memoization to avoid redundant cycle checks, and mention that cycle detection can be integrated with evaluation order.

1. Clarify requirements and assumptions

Ask about the scope: are formulas limited to simple references or can they include arithmetic? How often will cells be updated? This helps tailor the solution.

2. Design the data model

Represent each cell with its raw value (e.g., formula string) and a list of cells it depends on (precedents) and cells that depend on it (dependents). Use a graph structure to track dependencies.

3. Implement cycle detection on update

When setting a cell's value, parse its formula to extract dependencies. Then run a DFS from the cell to check if any dependency path leads back to it. If a cycle is detected, reject the update and return an error.

4. Handle propagation and evaluation

If no cycle, update the cell and recursively update all dependent cells, ensuring they are evaluated in topological order to avoid stale values.

5. Optimize and discuss trade-offs

Mention optimizations like caching evaluation results, incremental cycle detection, or using Tarjan's algorithm for strongly connected components. Discuss trade-offs between update latency and memory usage.

Key Points to Mention

  • Graph representation: cells as nodes, dependencies as directed edges.
  • Cycle detection using DFS with visited and recursion stack states.
  • Handling dynamic updates: incremental cycle detection vs. full re-evaluation.
  • Topological sorting for evaluation order to ensure correct values.
  • Error handling: how to report circular dependency to the user.
  • Performance considerations: time complexity of cycle detection (O(V+E)) and potential optimizations.

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