← HarveyAI Interview Insights

HarveyAI·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Interviewed for an MLE role at HarveyAI and part two of the coding round had me extending a spreadsheet implementation to support formulas, which meant figuring out dependency ordering via topological sort. Not the hardest thing I've done but it required actually thinking through the graph structure carefully.

Questions Asked (1)

Q1

Extend a spreadsheet implementation so that cells can contain formulas referencing other cells, and evaluate them in the correct dependency order.

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

Part one was straightforward cell storage stuff.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by modeling the spreadsheet as a directed graph where cells are nodes and formula references are edges. Then, use topological sorting to determine the evaluation order, detecting cycles to handle circular references. Finally, evaluate cells in that order, caching results to avoid redundant computations.

Pro tip: Mention that in real systems, you'd likely need incremental evaluation for performance, but for this problem, a full re-evaluation with topological sort is acceptable. Also, discuss how to handle errors like division by zero or invalid references gracefully.

1. Clarify requirements and assumptions

Ask about the scope: single vs. multiple sheets, supported formula operations, error handling, and whether cells can be updated dynamically. Confirm that formulas are simple arithmetic expressions referencing other cells.

2. Design the data model

Represent each cell with its raw content (value or formula) and a computed value. Build a dependency graph where an edge from cell A to cell B means A's formula references B. Use adjacency lists for efficiency.

3. Detect cycles and determine evaluation order

Perform a topological sort on the dependency graph. If a cycle is detected, mark those cells as errors (e.g., #CIRCULAR). Otherwise, the topological order gives a safe sequence for evaluation.

4. Evaluate formulas in order

Iterate through the topological order, parsing and evaluating each formula using the already computed values of its dependencies. Store results in the cell objects. Handle errors like division by zero or invalid references.

5. Discuss optimizations and trade-offs

Mention incremental evaluation: when a cell changes, only re-evaluate its dependents. Compare full re-evaluation vs. incremental, and discuss caching, memoization, and handling large spreadsheets.

Key Points to Mention

  • Directed graph representation of cell dependencies
  • Topological sorting for evaluation order
  • Cycle detection to handle circular references
  • Error propagation and handling (e.g., #DIV/0!, #REF!)
  • Caching/memoization to avoid redundant computations
  • Incremental evaluation for dynamic updates (trade-offs)

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