Part one was straightforward cell storage stuff.
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.
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.
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.
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.
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.
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.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.