← Harvey Interview Insights

Harvey·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Interviewed for a software engineering role at Harvey and got a design question that looked simple on the surface but had a pretty nasty follow-up baked in. The core problem was interesting enough that I actually enjoyed working through it, though the cycle detection part is where things got real.

Questions Asked (1)

Q1

Design an in-memory spreadsheet that supports setting cells to either integer values or formula expressions (referencing other cells), and implement getCell and setCell APIs. As a follow-up, detect and reject circular dependencies.

System DesignAlgorithms & Data StructuresData Modeling
Author's notes

I started with the data structure: a map from cell name to either a raw int or a list of dependencies plus an expression string.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then design a data model that stores raw cell content and a dependency graph. Implement getCell with lazy evaluation and memoization, and setCell with dependency updates. For circular dependency detection, use DFS with cycle detection during setCell.

Pro tip: Discuss the trade-offs between eager and lazy evaluation, and mention that using a topological order can optimize recalculations. Also, consider thread-safety if the spreadsheet is accessed concurrently.

1. Clarify Requirements

Ask about expected scale, concurrency, supported formula operations, and error handling. Confirm that formulas can reference other cells and that circular dependencies must be rejected.

2. Design Data Model

Propose storing each cell's raw input (integer or formula string) and a computed value. Maintain a dependency graph where edges represent references from a formula to other cells.

3. Implement getCell and setCell

For getCell, return the computed value, evaluating the formula if necessary. For setCell, parse the input, update the cell, and propagate changes to dependents. Use memoization to avoid redundant calculations.

4. Handle Circular Dependencies

During setCell, after updating the dependency graph, run a cycle detection algorithm (e.g., DFS) starting from the modified cell. If a cycle is found, reject the update and revert changes.

5. Discuss Optimizations and Edge Cases

Mention optimizations like topological sorting for batch updates, handling of invalid formulas, and concurrency control. Also, consider memory usage and scalability.

Key Points to Mention

  • Lazy evaluation with memoization to compute cell values on demand.
  • Dependency graph representation (adjacency list) to track cell references.
  • Cycle detection using DFS with recursion stack or topological sort.
  • Error handling for invalid formulas or references to non-existent cells.
  • Trade-offs between eager and lazy evaluation in terms of performance and complexity.
  • Thread-safety considerations if the spreadsheet is accessed concurrently.

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