Build a spreadsheet-like grid with cell editing and formula support, such as =SUM(A1,B1).
Asked in the Technical screen stage. Evaluate cell values with dependencies, using DFS as suggested by the author.
Implement evaluate_spreadsheet(edits). edits is a map from uppercase cell references to either an integer string or a formula in the form =SUM(arg1,arg2,...), where each argument is a cell reference or integer. A missing referenced cell has value 0. Return a map containing every edited cell and its evaluated integer value. Any cell involved in a dependency cycle, or depending on one, must have value "ERROR".
Examples: {"A1":"2","B1":"=SUM(A1,3)"} returns {"A1":2,"B1":5}. {"A1":"=SUM(B1)","B1":"=SUM(A1)"} returns {"A1":"ERROR","B1":"ERROR"}.
Constraints: At most 10,000 edited cells; formulas contain valid syntax and at most 20 arguments.
def evaluate_spreadsheet(edits):