Find the smallest value that appears in both sorted arrays.
You are given two integer arrays that are already sorted in non-decreasing order. Return the smallest integer that appears in both arrays. If the arrays have no value in common, return -1.
Because the arrays are sorted, the solution should take advantage of their order rather than checking every possible pair.
nums1 and nums2.-1.Example 1
Input
nums1 = [1,2,3], nums2 = [2,4]
Output
2
Explanation
The common values are {2}. The smallest one is 2.
Example 2
Input
nums1 = [1,2,3,6], nums2 = [4,5,7]
Output
-1
Explanation
There is no value that appears in both arrays.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.