← Fuse Energy Interview Insights
The history stack part sounds obvious in hindsight but I initially tried to just store cell values and forgot that SUM cells also have a formula attached.
Start by clarifying the existing data model and operations, then design a history stack that records enough state to revert both values and formulas. Walk through the undo logic for Set and SUM, discussing edge cases like multiple undos and memory trade-offs.
Pro tip: Mention that storing only the delta (previous value and formula) rather than full snapshots keeps memory O(1) per operation, and discuss how you'd handle undo of a SUM that depends on other cells.
Ask about the spreadsheet's cell representation (value + formula), how SUM is computed, and whether undo should be unlimited or bounded. Confirm that UNDO reverts the most recent Set or SUM, not other operations.
Propose a stack where each entry captures the operation type, the affected cell(s), and the previous state (value and formula). For SUM, record the previous value and formula of the target cell, and note if dependencies changed.
On UNDO, pop the top entry and restore the cell's previous value and formula. If the operation was a SUM, also restore any dependent cells if necessary, or recompute them.
Discuss empty stack behavior, multiple undos, memory usage, and whether to support redo. Consider if SUM formulas reference other cells and how undo affects them.
Walk through a sequence of Set, SUM, and UNDO operations to verify correctness. Mention unit tests for edge cases like undoing after no operations or undoing a SUM that changed multiple cells.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.