Code RoomCompare scan rows
EasyPrep Room Coding #4823

Compare scan rows

CodingAlgorithms & data structuresEntry–Mid~13 min

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.

Implement
first_mismatch_row(before: list[list[str]], after: list[list[str]]) → int
Examples
in[[["k","k"],["k","m"]],[["k","k"],["k","m"]]]out-1
in[[["a","b","c"],["d","e","f"]],[["a","b","c"],["d","x","f"]]]out1
in[[["a","?"],["b","b"]],[["a","z"],["b","c"]]]out1
What a strong answer looks like

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.

0:00 of about 13 min
InputExpectedGot
[[["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