Evaluate Spreadsheet Cells That Reference Other Cells
Last updated: November 29, 2026
Quick Overview
Each cell holds either an integer or a formula that is the sum of other cells, like '=A1+B2+5'. Given a mapping of cell names to their contents, return the numeric value of every cell, or report the cells involved in a circular reference as errors.
Meta
November 29, 20260
0
0 solved
Each cell holds either an integer or a formula that is the sum of other cells, like '=A1+B2+5'. Given a mapping of cell names to their contents, return the numeric value of every cell, or report the cells involved in a circular reference as errors.
A Meta onsite question in the style of building a lightweight spreadsheet inside a web tool such as an internal dashboard editor. The interviewer checks parsing, building a dependency graph from formulas, evaluating in topological order, and marking every cell that cannot be resolved because of a cycle.
What the Interviewer Expects
- Parse formulas into referenced cells and a constant term
- Build edges from each referenced cell to the formula cell
- Evaluate in topological order with Kahn's algorithm
- Mark cells on or downstream of a cycle as errors
- Treat references to empty cells as zero (after clarifying)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you recompute only affected cells when one cell is edited?
- How would you support functions like SUM(A1:A10) with ranges?
- How do you distinguish cells on a cycle from cells that merely depend on one?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
cells, a dict like{"A1": "5", "B1": "=A1+3", "C1": "=B1+A1"}. - Formulas are
=followed by+-separated terms, each a cell name or integer. - Output: dict of cell to integer value, wi...
High-Level Design
- Parse. For each formula split on
+; numeric terms add to a constant, others are references. - Graph. Edge
ref -> cellfor each reference to a defined cell. In-degree of a cell is its n...