left and right, each sorted in non-decreasing order. Values may repeat within a list.
Return the smallest number that appears in both lists at least once. If there is no such number, return -1.
Try to do it without extra memory by using the fact that both lists are already sorted.left=[2, 5, 5, 9, 14], right=[1, 5, 9, 20] → 5
The shared numbers are 5 and 9; the smaller one is 5.
left=[3, 6, 8], right=[4, 7, 10] → -1
No number appears in both lists, so the answer is -1.
left=[1], right=[1, 1, 2] → 1
left=[2, 5, 5, 9, 14], right=[1, 5, 9, 20]
5
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.