Spreadsheet formula references
A spreadsheet pastes a copied formula into another cell, and the paste has to move the references the formula holds. A reference is an optional dollar sign, one or more uppercase letters naming the column, an optional dollar sign, then one or more digits naming the row, as in A1, $A1, A$1 or $A$1. A dollar sign pins the half that follows it, so that half does not move. Given formula, row_delta and col_delta, return the formula with every unpinned row shifted by row_delta and every unpinned column shifted by col_delta, with every other character copied through unchanged. Columns run A to Z, then AA, AB and onward, so column 27 is AA. Letters with no digits after them are a function name, not a reference. The deltas never push a reference above row 1 or left of column A.
shift_formula_refs(formula: str, row_delta: int, col_delta: int) → str["=A1+B2",2,0]out"=A3+B4"["=$A$1+A1",1,1]out"=$A$1+B2"["=SUM(A1:A3)*2",0,1]out"=SUM(B1:B3)*2"State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
["=A1+B2",2,0]"=A3+B4"not run yetsample["=$A$1+A1",1,1]"=$A$1+B2"not run yetsample["=SUM(A1:A3)*2",0,1]"=SUM(B1:B3)*2"not run yetsample