Compare scan rows
A press operator compares two scans of the same calibration sheet, one taken before a maintenance stop and one after. Each scan is a grid of single character ink codes, one code per cell, and the two scans need not even agree on how many rows they have. A row matches when both scans have that row, the two rows hold the same number of cells, and every cell carries the same code. The scanner writes '?' for a cell it could not read, and a '?' on either side never counts as a difference. Return the index of the lowest numbered row that does not match. A row that only one scan has counts as a difference. Return -1 when every row matches. Codes are case sensitive.
first_mismatch_row(before: list[list[str]], after: list[list[str]]) → int[[["k","k"],["k","m"]],[["k","k"],["k","m"]]]out-1[[["a","b","c"],["d","e","f"]],[["a","b","c"],["d","x","f"]]]out1[[["a","?"],["b","b"]],[["a","z"],["b","c"]]]out1State 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.
[[["k","k"],["k","m"]],[["k","k"],["k","m"]]]-1not run yetsample[[["a","b","c"],["d","e","f"]],[["a","b","c"],["d","x","f"]]]1not run yetsample[[["a","?"],["b","b"]],[["a","z"],["b","c"]]]1not run yetsample