Skip to content

Practice Design Spreadsheet

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3484
LeetCode Problem

Design Spreadsheet

Problem Statement

Implement Spreadsheet(rows) with columns A through Z and rows numbered from 1; all cells start at zero and store integers from 0 through 10^5. setCell(cell, value) updates a reference such as A1 or B10, and resetCell(cell) sets it back to zero. getValue(formula) evaluates a string of the form =X+Y, where each operand is a cell reference or a nonnegative integer, and returns the sum. An unset cell contributes zero.

Source: Design Spreadsheet on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
["Spreadsheet", "getValue", "setCell", "getValue", "setCell", "getValue", "resetCell", "getValue"] [[3], ["=5+7"], ["A1", 10], ["=A1+6"], ["B2", 15], ["=A1+B2"], ["A1"], ["=A1+B2"]]
Output
[null, 12, null, 16, null, 25, null, 15]

Constraints

1 <= rows <= 10^3
0 <= value <= 10^5
The formula is always in the format "=X+Y", where X and Y are either valid cell references or non-negative integers with values less than or equal to 10^5.
Each cell reference consists of a capital letter from 'A' to 'Z' followed by a row number between 1 and rows.
At most 10^4 calls will be made in total to setCell, resetCell, and getValue.

Related LeetCode Problems

Practice more problems similar to Design Spreadsheet.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.