Spreadsheet Formula Evaluator
Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines for a small spreadsheet engine.
Problem
Implement a spreadsheet with cell labels such as A1 and B10. The spreadsheet supports setting cells to integers or formulas, retrieving evaluated values, and detecting cycles.
A formula is a +-separated expression containing non-negative integer literals and/or cell labels. Operators other than + are not required.
Supported commands:
SET label value: setlabelto an integer or formula. ReturnOKif the assignment does not create a dependency cycle; otherwise leave the spreadsheet unchanged and returnERROR.GET label: return the evaluated integer value oflabel. ReturnERRORif the cell is unset or cannot be evaluated.
Cell dependencies are evaluated lazily or eagerly as you choose, but GET must always reflect the latest committed cell values.
Complete solveSpreadsheetFormulaEvaluator. It has one parameter, String input, containing newline-separated commands. Return the stdout payload as an array of lines, without trailing newline characters.
1Example 1
A2 references A1, and A3 references both A1 and A2.
2Example 2
The third command would create A1 -> B1 -> A1, so it is rejected and the previous values remain active.
Constraints
Limits and guarantees your solution can rely on.
Cell labels consist of uppercase letters followed by digits, such as A1 or B10.
Formula expressions only need to support addition with +.
Assignments that introduce a cycle must be rejected.