Spreadsheet circular reference
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.
circular_formula_exists(links: list[str]) → bool[["C4>A1","C4>B2"]]outfalse[["A1>B1","B1>C1","C1>A1"]]outtrue[["A1>A1"]]outtrueState 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.
[["C4>A1","C4>B2"]]falsenot run yetsample[["A1>B1","B1>C1","C1>A1"]]truenot run yetsample[["A1>A1"]]truenot run yetsample