Recompute Dependent Formulas (Topological)

Problem A spreadsheet-style document has cells that hold either literal values or formulas referencing other cells. When a referenced value changes, recompute all dependent formula cells in the correct order, and detect circular references.

Input / Output

  • Input: a set of cells with their formula dependencies, plus a change to one cell's value.
  • Output: the updated values of all affected cells in a valid recomputation order, or an error if a dependency cycle exists.

Constraints

  • A cell must be recomputed only after every cell it depends on.
  • Circular references (A depends on B depends on A) must be detected and reported rather than looping forever.

Example

  • B1 = A1 + 1, C1 = B1 * 2. When A1 changes, recompute B1 then C1 in that order.
added …
LeaderboardSalaryAccount