Back to problems Sign in to unlock
Leetcode
Easy
Arrays
Binary Search
Two Pointers
Minimum Common Value
Find the smallest value that appears in both sorted arrays.
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement
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.
Input Format
- Two sorted integer arrays,
nums1andnums2. - Each array may contain duplicates.
- Values are integers.
Output Format
- Return the smallest integer present in both arrays.
- If no common value exists, return
-1.
Constraints
- The arrays are sorted in non-decreasing order.
- Duplicates may appear in either array.
- Aim for better than brute force pairwise comparison.
Examples
Sample cases returned by the problem API.
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
Unlock deeper context for this problem
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.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.