Citadel interview question
Build an in-memory spreadsheet with numeric cells and arithmetic formulas
- Company:
- Citadel
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- October 28, 2026
Problem
Implement a simplified in-memory spreadsheet. Cells are identified by names such as A1 or B7. The spreadsheet supports three operations:
set_cell(name, value): store a numeric value in the cell.set_formula(name, formula): store a formula in the cell. A formula is an arithmetic expression that combines numbers and other cell names with addition, subtraction, multiplication and division (for exampleA1 + B1 * 2).get_cell(name): return the current computed value of the cell, reflecting the latest values of every cell it depends on.
Follow-up: formulas can be nested (a formula may reference cells that themselves hold formulas) and can form circular references, either a direct self-reference (A1 refers to A1) or an indirect cycle such as A1 -> B1 -> C1 -> A1. Detect these and report them as an error instead of looping forever. Be ready to discuss where the computation should happen (in get_cell or in the setters) and which design fits a workload with few writes and many reads.
Example 1
Input:
set_cell("A1", 5)
set_cell("B1", 3)
set_formula("C1", "A1 + B1 * 2")
get_cell("C1")
set_cell("A1", 10)
get_cell("C1")
Output:
11
16
Explanation: C1 is 5 + 3 * 2 = 11; after A1 changes to 10 the same formula gives 10 + 6 = 16.
Example 2
Input:
set_formula("A1", "B1 + 1")
set_formula("B1", "C1 * 2")
set_formula("C1", "A1 - 3")
get_cell("A1")
Output:
error: circular reference
Explanation: A1 depends on B1, which depends on C1, which depends on A1 again.
Constraints
- Not stated; ask the interviewer.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern