Ctrl K

Which Gauge Skipped

Easy
Two identical gauges take measurements at the same time: first[i] and second[i] are the i-th readings of the first and second gauge. This kind of gauge sometimes fails: it loses exactly one reading. Every reading after the lost one moves one position to the left, and the last position gets a random number that is guaranteed to differ from the lost reading. For example, [1, 2, 3, 4, 5] could become [1, 2, 4, 5, 8] after losing the 3. At most one gauge failed, and the data fits at least one story: no failure, the first gauge failed, or the second gauge failed. Return 1 or 2, the number of the gauge that failed. If nothing failed, or the data cannot tell which gauge failed, return -1.
Example 1
first=[7, 3, 9, 4], second=[7, 9, 4, 1] → 2

The second gauge lost the 3: 9 and 4 shifted left and a random 1 appeared at the end. The first gauge's data cannot be explained that way.

Example 2
first=[5, 5, 8], second=[5, 5, 2] → -1

Only the last value differs. Either gauge could have lost it and put a random value in its place, so the faulty one cannot be told apart.

Example 3
first=[4, 6, 6, 2], second=[4, 6, 6, 2] → -1

The data matches, so there was no failure.

Constraints
  • len(first) = len(second)
  • 1 ≤ len(first) ≤ 100
  • 1 ≤ first[i], second[i] ≤ 100
  • The data is explained by no failure or by exactly one failed gauge
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasyMerge Into the Spare Tail EasyZeros to the Back EasyValues in Both Lists Easy
loading Python…
Input
first=[7, 3, 9, 4], second=[7, 9, 4, 1]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.