Design and implement a spreadsheet system called OpenSheet that supports cell values, formulas, and automatic dependency resolution. The system must handle cell references, evaluate formulas, and detect circular dependencies. This problem tests your ability to build a dependency graph, perform topological evaluation, and optimize for different performance requirements.
Implement a Spreadsheet class that supports setting values/formulas and getting computed values with real-time dependency resolution.
Spreadsheet() - Initializes the spreadsheetsetCell(key: str, value: str) - Sets a cell to a value or formula"42", "3.14")= and can reference other cells (e.g., "=A1 + A2")+, -, *, /A1, B2, Z99)getCell(key: str) -> float - Returns the computed value of a cell0 or None for non-existent cells (implementation choice)`spreadsheet = Spreadsheet()
spreadsheet.setCell('A1', '1') spreadsheet.setCell('A2', '2')
spreadsheet.setCell('A3', '=A1 + A2') # A3 = 1 + 2 = 3 spreadsheet.setCell($L41, $L42) $L43 spreadsheet.setCell($L44, $L45) $L46 $L48(spreadsheet.getCell($L49)) $L4a $L4b(spreadsheet.getCell($L4c)) $L4d $L4e(spreadsheet.getCell($L4f)) $L50 spreadsheet.setCell($L52, $L53) $L54(spreadsheet.getCell($L55)) $L56 $L57(spreadsheet.getCell($L58)) $L59 $L5b(spreadsheet.getCell($L5c)) $L5d