Code Room
CodingHardcod-g452
Subject Expression evaluationLevel Senior–Staff~45 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.