In-memory Spreadsheet with formula recalc

seniorjava · AI-off35:00
  1. 1Clarify
  2. 2Code
  3. 3Test
  4. 4Optimize
  5. 5Done

Problem

Build an in-memory spreadsheet. set(cell, expr) stores a literal number or a formula like "=A1+A2" (cell references and + only). get(cell) returns the evaluated integer value, recomputed from current inputs. Updating an input must be reflected by later reads.

1Your goal now — Clarify

Restate the problem in one sentence and list the edge cases — before writing any code.

Say your opening out loud to unlock coding

Then keep talking — restate the problem + the edge cases in your own words.

Let me make sure I understand the problem, then I'll walk through my approach.

checking microphone…

Self-check

Hints / what this doesn't test

This is an Opendoor-flavored applied problem: a small system with state and recomputation, not a puzzle. Restate it back before coding — "So a cell is either a number or a +-formula over other cells, and get always reflects the latest inputs?"

What this problem does not test (say so out loud): multiplication / operator precedence, ranges like A1:A3, and cycle handling are out of scope here — but a senior names the cycle case (A1=B1, B1=A1) as a known gap and how they'd detect it (visited-set during evaluation).

Solution.javaauto-runs ~0.8s after you pause

Tests

○ Not run yet — edit the code or press Run
  • literal
  • formula_sum
  • chained
  • + 1 hidden test — revealed once the visible ones pass
Step 1 of 5: Clarify