Code RoomSpreadsheet circular reference
EasyPrep Room Coding #4725

Spreadsheet circular reference

CodingAlgorithms & data structuresEntry–Mid~17 min

A spreadsheet engine refuses to recalculate a sheet that holds a circular reference. It hands you `links`, where each entry is a string like "C4>A1", meaning the formula in cell C4 reads the value in cell A1. Every cell named on either side of a `>` belongs to the sheet, and a cell that is never named on the left has no formula of its own. Return true when following those reads can arrive back at the cell the chain started from, and false when every chain of reads ends at a cell with no formula. A formula that reads its own cell is circular. The same read may be listed more than once, and the sheet may hold several independent groups of formulas.

Implement
circular_formula_exists(links: list[str]) → bool
Examples
in[["C4>A1","C4>B2"]]outfalse
in[["A1>B1","B1>C1","C1>A1"]]outtrue
in[["A1>A1"]]outtrue
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 17 min
InputExpectedGot
[["C4>A1","C4>B2"]]falsenot run yetsample
[["A1>B1","B1>C1","C1>A1"]]truenot run yetsample
[["A1>A1"]]truenot run yetsample