Code RoomSpreadsheet evaluator
HardPrep Room Coding #1021

Spreadsheet evaluator

CodingAlgorithms & data structuresSenior–Staff~45 min

Evaluate a tiny spreadsheet. You get `cells`, a list of [name, formula] pairs. A formula is either a plain integer literal (e.g. '5') or a sum expression of the form 'A+B+C' where each operand is either an integer or another cell name (operands joined by '+'). Resolve every cell to its integer value, handling dependencies in any order. If there is a cyclic dependency, return the string 'CYCLE'. Otherwise return a list of [name, value] sorted by name ascending. Cell names are non-empty alphanumeric strings; every referenced name is defined.

Implement
eval_sheet(cells: list[list]) → object
Examples
in[[["A","1"],["B","A+2"],["C","A+B"]]]out[["A",1],["B",3],["C",4]]
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 45 min
InputExpectedGot
[[["A","1"],["B","A+2"],["C","A+B"]]][["A",1],["B",3],["C",4]]not run yetsample