In-Memory Spreadsheet Values
Problem statement
Implement the core of an in-memory spreadsheet. Each cell stores either an integer literal, a two-integer addition expression, or its default blank value.
Process each operation in order:
["SET", cell, value]: storevalueincell. A non-empty value is either a signed integer literal such as-9or an expression such as=100+2. Settingvalueto the empty string resets the cell to its default blank value.["GET_RAW", cell]: append the cell's stored text to the result. Append the empty string when the cell is blank.["GET_COMPUTED", cell]: append the cell's displayed value to the result. An integer displays its decimal value, and an expression displays the decimal sum of its two integer operands. Append the empty string when the cell is blank.
Only GET_RAW and GET_COMPUTED operations produce output. Return their results in operation order.
Expressions contain integer literals only. They do not reference other cells.
Function
runSpreadsheet(operations: String[][]) → String[]Examples
Example 1
operations = [["SET","A1","23"],["SET","B2","=2+8"],["GET_RAW","A1"],["GET_COMPUTED","B2"],["GET_RAW","B2"]]return = ["23","10","=2+8"]A1 stores the integer text "23". The computed view of B2 evaluates 2 + 8, while its raw view preserves "=2+8".
Example 2
operations = [["SET","A1","-9"],["GET_COMPUTED","A1"],["SET","A1",""],["GET_RAW","A1"],["GET_COMPUTED","A1"]]return = ["-9","",""]Setting an empty value resets A1. Both views then return the default blank value.
Example 3
operations = [["SET","C3","=100+2"],["SET","D4","=-9+23"],["GET_COMPUTED","C3"],["GET_COMPUTED","D4"],["SET","C3","7"],["GET_RAW","C3"],["GET_COMPUTED","C3"]]return = ["102","14","7","7"]Both expression cells are evaluated from their two literal operands. Overwriting C3 with "7" changes both its raw and computed views.
Constraints
1 <= operations.length <= 10^5.- Each cell identifier is a non-empty string of at most
20uppercase letters and digits. - Each operation has one of the documented forms.
- Every non-empty value is either a signed integer from
-999through999, or an expression of the form=a+bwhere both operands are signed integers in that range. - Values and expressions contain no whitespace.