← Harvey Interview Insights

Harvey·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Apr 2026

Summary

Interviewed for an MLE role at HarveyAI and hit a coding problem that extended a basic spreadsheet implementation to support formulas with cell dependencies, which meant you had to figure out evaluation order using a topological sort.

Questions Asked (1)

Q1

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

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

Part one was fine, just a grid with static values.

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 formula references are edges, then use topological sorting to evaluate cells in dependency order. Detect cycles to handle circular references gracefully, and discuss trade-offs between eager and lazy evaluation for performance.

Pro tip: Mention that in production systems like Excel, incremental evaluation and caching are crucial for performance, and that cycle detection should be done during graph construction to fail fast. Also, relate this to ML pipelines where DAGs ensure correct execution order.

1. Clarify requirements and constraints

Ask about expected scale (number of cells, formula complexity), whether formulas can reference ranges, and how to handle errors or circular references. Confirm if evaluation should be eager or lazy.

2. Design the data model and dependency graph

Represent each cell as a node with its raw content (value or formula) and parsed dependencies. Build a directed graph where an edge from A to B means A depends on B.

3. Implement topological sort and cycle detection

Use Kahn's algorithm or DFS to topologically sort the graph. If a cycle is detected, mark involved cells as errors (e.g., #CIRCULAR).

4. Evaluate cells in topological order

Process cells in sorted order, computing each formula using already-evaluated dependencies. Cache results to avoid recomputation.

5. Discuss trade-offs and optimizations

Compare eager vs. lazy evaluation, incremental updates when a cell changes, and handling of large spreadsheets. Mention potential parallelization for independent branches.

Key Points to Mention

  • Directed acyclic graph (DAG) representation of cell dependencies
  • Topological sorting algorithms (Kahn's or DFS) for evaluation order
  • Cycle detection to handle circular references
  • Caching and incremental evaluation for performance
  • Trade-offs between eager and lazy evaluation
  • Error propagation and handling of invalid formulas

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