Maintain Spreadsheet Cells with Persistent Sum Dependencies
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Other
### Problem
Implement Excel(height,width), with rows 1..height and columns A..width initially zero. set(row,column,val) replaces a cell value and removes its old formula; get returns its current value. sum(row,column,numbers) replaces the cell with a persistent sum formula and returns its current value. References are single cells such as A2 or inclusive rectangles such as A1:C3. Count repeated and overlapping references with multiplicity. Later dependency changes affect formula values; cycles never occur.
CURATOR local practice clarification: each value returned by get or sum fits signed 32-bit int. The original source does not state this output-fit promise despite using int-returning methods. All original input bounds and native methods are retained; this clarification requires independent reviewer acceptance.
```cpp
class Excel {
public:
Excel(int height, char width);
void set(int row, char column, int val);
int get(int row, char column);
int sum(int row, char column, vector<string> numbers);
};
```
### Examples
**Example 1:**
```text
Excel(2,'C'); set(1,'A',3); sum(2,'C',["A1","A1:B1"]) -> 6; set(1,'B',4); get(2,'C') -> 10
Explanation: A1 is counted twice and the formula remains active.
```
**Example 2:**
```text
Excel(1,'C'); set(1,'A',2); sum(1,'B',["A1"]) -> 2; set(1,'B',7); set(1,'A',9); get(1,'B') -> 7
Explanation: set replaces the former dependency.
```
### Constraints
- Sheet height: 1..26. The final column width is A..Z. Every row argument is within 1..height and every column argument is within A..width. Literal val: -100..100. A sum has 1..5 cell or rectangle reference strings in the stated format. The combined set/get/sum call count is at most 100. The source promises acyclic references. The labeled CURATOR output-fit clarification above remains additional to these original bounds.
### Clarifying Questions
Preserve persistent formulas, reference multiplicity, replacement semantics and the source's no-cycle promise; assess the labeled numeric clarification.
```hint Read the boundary condition
Would returning a sum once be enough if its referenced cells can later change?
```
### Contract considerations
Preserve persistent formulas, reference multiplicity, replacement semantics and the source's no-cycle promise; assess the labeled numeric clarification.
Overview: Maintain Spreadsheet Cells with Persistent Sum Dependencies. Implement Excel(height,width), with rows 1..height and columns A..width initially zero.
Maintain Spreadsheet Cells with Persistent Sum Dependencies
Airbnb
Jul 4, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0
Problem
Implement Excel(height,width), with rows 1..height and columns A..width initially zero. set(row,column,val) replaces a cell value and removes its old formula; get returns its current value. sum(row,column,numbers) replaces the cell with a persistent sum formula and returns its current value. References are single cells such as A2 or inclusive rectangles such as A1:C3. Count repeated and overlapping references with multiplicity. Later dependency changes affect formula values; cycles never occur.
CURATOR local practice clarification: each value returned by get or sum fits signed 32-bit int. The original source does not state this output-fit promise despite using int-returning methods. All original input bounds and native methods are retained; this clarification requires independent reviewer acceptance.
class Excel {
public:
Excel(int height, char width);
void set(int row, char column, int val);
int get(int row, char column);
int sum(int row, char column, vector<string> numbers);
};
Examples
Example 1:
Excel(2,'C'); set(1,'A',3); sum(2,'C',["A1","A1:B1"]) -> 6; set(1,'B',4); get(2,'C') -> 10
Explanation: A1 is counted twice and the formula remains active.
Example 2:
Excel(1,'C'); set(1,'A',2); sum(1,'B',["A1"]) -> 2; set(1,'B',7); set(1,'A',9); get(1,'B') -> 7
Explanation: set replaces the former dependency.
Constraints
Sheet height: 1..26. The final column width is A..Z. Every row argument is within 1..height and every column argument is within A..width. Literal val: -100..100. A sum has 1..5 cell or rectangle reference strings in the stated format. The combined set/get/sum call count is at most 100. The source promises acyclic references. The labeled CURATOR output-fit clarification above remains additional to these original bounds.
Clarifying Questions Guidance
Preserve persistent formulas, reference multiplicity, replacement semantics and the source's no-cycle promise; assess the labeled numeric clarification.
Contract considerations
Preserve persistent formulas, reference multiplicity, replacement semantics and the source's no-cycle promise; assess the labeled numeric clarification.