FastPrepFirst Missing Number in a Consecutive Array
Problem · Array

First Missing Number in a Consecutive Array

Learn this problem
EasyArista Networks logoArista NetworksNEW GRADOA

Problem 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[]) → int

Examples

Example 1

nums = [11,12,14,15,16]return = 13

The sequence begins 11, 12, but the next expected value 13 is absent.

Example 2

nums = [4,7,8]return = 5

Both 5 and 6 are missing between the endpoints, so the first missing value is 5.

Example 3

nums = [-3,-2,-1,1]return = 0

The 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 valid i.
  • At least one integer strictly between the first and last array values is missing.

More Arista Networks problems

drafts saved locally
public int firstMissingNumber(int[] nums) {
  // Write your code here
}
nums[11,12,14,15,16]
expected13
checking account