Problem · Array
First Missing Number in a Consecutive Array
Learn this problemProblem statement
You are given a sorted, strictly increasing integer array nums. At least one integer strictly between nums[0] and nums[nums.length - 1] is absent from the array.
Return the smallest missing integer in that inclusive numeric span.
Function
firstMissingNumber(nums: int[]) → intExamples
Example 1
nums = [11,12,14,15,16]return = 13The sequence begins 11, 12, but the next expected value 13 is absent.
Example 2
nums = [4,7,8]return = 5Both 5 and 6 are missing between the endpoints, so the first missing value is 5.
Example 3
nums = [-3,-2,-1,1]return = 0The values remain consecutive through -1; the first gap is 0.
Constraints
2 <= nums.length <= 100000.-10^9 <= nums[i] <= 10^9.nums[i] < nums[i + 1]for every validi.- At least one integer strictly between the first and last array values is missing.