Return the Least Value Present in Both Sorted Arrays
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
Given positive integer arrays `nums1` and `nums2`, both sorted in nondecreasing order, return the smallest value occurring in both. One occurrence in each is sufficient. Return `-1` if there is no common value.
```cpp
class Solution {
public:
int getCommon(vector<int>& nums1, vector<int>& nums2);
};
```
### Examples
**Example 1:**
```text
Input: nums1 = [1,1,5,8], nums2 = [2,5,5]
Output: 5
Explanation: Five is the first shared value; duplicate occurrences do not change the result.
```
**Example 2:**
```text
Input: nums1 = [1,3], nums2 = [2,4]
Output: -1
Explanation: The two arrays have no shared value.
```
### Constraints
- Each array has 1 through 100000 entries.
- Values lie in [1,10^9].
- Both arrays are sorted nondecreasingly.
### Clarifying Questions
- Are duplicate values allowed? Yes.
- Do multiplicities have to match? No; one occurrence in each array is enough.
- Are the inputs already sorted? Yes.
- Is a value or an index returned? The common value.
```hint Check the boundary
Check arrays whose common value appears several times in one array.
```
Overview: Find the smallest value present in both sorted arrays, allowing duplicates and returning -1 when there is no common value.