Topological Sort (Cell Dependencies)

Problem

Cells form a dependency graph (A depends on B). Given the dependencies, compute a valid recompute order, and detect cycles.

Input / Output

  • Input: cells and their dependency edges (A depends on B).
  • Output: a recompute order in which every cell follows the cells it depends on, or a report that a cycle exists.

Constraints

  • Up to 10^4 cells.

Example

A->B, B->C => recompute C,B,A; A->B, B->A -> cycle
added …
LeaderboardSalaryAccount