Spreadsheet Formula Dependencies
Updated
Problem statement
Start with an empty in-memory spreadsheet. Each cell holds either an integer or a formula referring to other cells. Process operations in order and return one string for every operation.
In this exercise, each formula has two operands and one operator. Each operand can be a cell ID or an integer. A formula can refer to another cell that also contains a formula.
["SET", cell, value]replaces the cell with the integervalueand returns"OK".["FORMULA", cell, left, operator, right]proposes replacing the cell withleft operator right. The operator is+,-,*, or/. Accept the replacement and return"OK"unless it introduces a direct or indirect circular reference. In that case, return"CYCLE"and leave the spreadsheet completely unchanged.["GET", cell]returns the cell's current value as a decimal string. A cell that has never been assigned has value0. Values must reflect every earlier accepted update, including updates to indirect dependencies.
Arithmetic is integer arithmetic. Division truncates toward zero. Return "ERROR" when evaluating a cell requires division by zero, either in that cell’s formula or in a cell it depends on. Such a formula may be stored successfully; the error is reported when its value is read. A later update can repair it.
Using the same cell more than once in a formula is legal and is not itself a cycle. Replacing a formula removes its old dependency relationships. Rejected updates must not change definitions or cached values.
In a read-heavy workload, how can per-query memoization be improved with a persistent cache and reverse dependencies? Explain which cached cells must be invalidated after an accepted update and how overwriting a formula changes the dependency graph.
Function
runSpreadsheet(operations: String[][]) → String[]Examples
Example 1
operations = [["SET","A1","3"],["FORMULA","B1","A1","*","2"],["GET","B1"],["SET","A1","5"],["GET","B1"]]return = ["OK","OK","6","OK","10"]The formula in B1 doubles the current value of A1. Its second read must use the updated value rather than a stale cached result.
Example 2
operations = [["FORMULA","A1","B1","+","B1"],["GET","A1"],["SET","B1","4"],["GET","A1"],["FORMULA","B1","A1","+","1"],["GET","B1"]]return = ["OK","0","OK","8","CYCLE","4"]Repeating B1 in the first formula is legal. Replacing B1 with a reference to A1 would create a cycle, so that update is rejected and B1 remains 4.
Example 3
operations = [["SET","Z1","0"],["FORMULA","A1","7","/","Z1"],["GET","A1"],["SET","Z1","2"],["GET","A1"],["FORMULA","B1","-7","/","2"],["GET","B1"]]return = ["OK","OK","ERROR","OK","3","OK","-3"]The stored formula initially divides by zero. Updating its denominator repairs it. Both positive and negative division truncate toward zero.
Constraints
0 <= operations.length <= 256.- At most
64different cell IDs appear across all operations. Each one matches[A-Z][A-Z0-9]{0,3}. - Every operation has exactly one of the forms described above. Each number is written as a plain decimal integer: an optional leading minus sign, and no leading zeros except for
0itself. Its absolute value is at most10^6. - At every step, each part of a calculation that does not depend on a division by zero has an integer value in
[-10^9, 10^9]. - An operand never holds parentheses or extra operators. To build a larger expression, refer to cells that hold formulas. All IDs and operators are case-sensitive.
More Citadel Phone Screen questions
- Merge Price-Delta FeedsPHONE SCREEN · Seen Dec 2026
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Versioned Social NetworkOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Spreadsheet With Dependent CellsCharacter.AI · PHONE SCREEN
- Evaluate Live Spreadsheet ExpressionsStrala · PHONE SCREEN
- Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions
- Agent Task Dependency TrackerPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Spreadsheet Formula DependenciesAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Clone an Undirected Graph StateApple · OAApple interview questions
- Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
- Spreadsheet Formula EvaluatorHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Bus RoutesUiPath · PHONE SCREEN
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences