Compare scan rows

Write codeEasy13 min

Your task

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.

Examples

first_mismatch_row(before: list[list[str]], after: list[list[str]]) -> int
Example 1
Inputfirst_mismatch_row([["k", "k"], ["k", "m"]], [["k", "k"], ["k", "m"]])
Output-1
Example 2
Inputfirst_mismatch_row([["a", "b", "c"], ["d", "e", "f"]], [["a", "b", "c"], ["d", "x", "f"]])
Output1
Example 3
Inputfirst_mismatch_row([["a", "?"], ["b", "b"]], [["a", "z"], ["b", "c"]])
Output1