A deep-space probe transmits altitude readings once per tick over two independent, normally redundant telemetry channels. Under normal operation both channels report an identical sequence of readings, one per tick. At most one of the two channels can suffer a single-tick dropout: at some tick it fails to record anything, and every reading it reports from that tick onward is really the value meant for the next tick -- the rest of that channel's log is permanently shifted forward by one position relative to the channel that keeps working correctly. Because of the shift, the affected channel's very last logged value corresponds to a tick that the other channel never reported, so it carries no confirming information; if the two logs first disagree exactly at their last tick, there is genuinely not enough evidence to tell which channel is at fault.
Given both channels' full logs, each of length n, determine which channel suffered the dropout.
Line 1: a single integer n. Line 2: n space-separated integers -- channel 1's log. Line 3: n space-separated integers -- channel 2's log.
Print a single integer: 1 if channel 1 is the one that dropped a reading, 2 if channel 2 is the one that dropped a reading, or -1 if the two logs are identical, or if the first tick where they disagree is the very last tick (so the channel at fault cannot be determined).
Example 1
Input
5 3 7 1 9 4 3 7 9 4 6
Expected
2
Explanation
Ticks 0 and 1 agree (3 and 7 on both channels). Tick 2 is the first disagreement: channel 1 reports 1 while channel 2 reports 9. Testing whether channel 2 dropped a reading at tick 2: channel 2's remaining readings (9, 4) match channel 1's readings one tick later (ticks 3 and 4: 9, 4), confirming channel 2 lost a reading there. Channel 2's final entry, 6, is simply whatever it reported next and is never checked against anything, so the answer is 2.
Example 2
Input
6 1 2 3 5 6 9 1 2 3 4 5 6
Expected
1
Explanation
Ticks 0 through 2 agree (1, 2, 3). Tick 3 is the first disagreement: channel 1 reports 5 while channel 2 reports 4. Testing whether channel 1 dropped a reading at tick 3: channel 1's remaining readings (5, 6) match channel 2's readings one tick later (ticks 4 and 5: 5, 6), confirming channel 1 lost a reading there. Channel 1's final entry, 9, is unconstrained, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →