First Missing Number in a Consecutive Array
Reported by candidates from Arista Networks's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The guarantee in this Arista Networks question is the whole game: at least one integer strictly between nums[0] and the last element is missing, so you never have to handle the "no gap" case. Reported in September 2026, it's a sorted, strictly increasing array and you return the first missing value in the span. It looks like an easy scan, but the 100000 length and values up to 10^9 push you toward binary search. If you blank on the OA, StealthCoder runs invisibly as a safety net while you work through it.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: in a gap-free run, nums[i] - i stays equal to nums[0]. The first index where nums[i] - i exceeds nums[0] marks the gap, and the answer is nums[0] + i. Because the array is sorted and strictly increasing, that predicate is monotonic, so binary search finds the first index where nums[i] != nums[0] + i in O(log n). A plain linear scan checking nums[i+1] - nums[i] > 1 also works and returns nums[i] + 1. The common pitfall is returning the wrong side of the gap, like nums[i+1] instead of nums[i] + 1. Negatives are fine since you only use differences, as in [-3,-2,-1,1] returning 0. Don't use a hash set, it wastes memory for no reason. If the live OA has you freezing on the monotonic predicate, StealthCoder can give you the binary search while you keep your composure.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill First Missing Number in a Consecutive Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Arista Networks's OA.
Arista Networks reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
First Missing Number in a Consecutive Array FAQ
How hard is the First Missing Number question really?+
Easy to medium. The linear scan is a few lines and passes correctness. The only extra step is recognizing that nums[i] - i is constant until the gap, which lets you binary search. Most candidates get the scan quickly, so expect the follow-up to be about complexity.
What's the trick to solve it fast?+
Compare each value to nums[0] + i. While they match, there's no gap. The first index where nums[i] is larger than nums[0] + i is the gap, and the answer is nums[0] + i. That predicate is monotonic, so binary search applies.
Do I need binary search or is a linear scan enough?+
A linear scan is O(n) and fits n up to 100000 easily. Binary search gives O(log n) and is the cleaner answer if the interviewer asks to optimize. Write the scan first so you have a correct answer, then upgrade if you have time.
What edge cases should I test?+
Negative values like [-3,-2,-1,1] returning 0, a gap right after the first element like [4,7,8] returning 5, and a gap at the very end. Also check large values near 10^9 so your arithmetic doesn't misbehave. The guarantee means you never need a no-gap return.
How do I prepare for this in 48 hours?+
Write both versions from scratch: the linear gap check and the binary search on nums[i] - i versus nums[0]. Run the three examples by hand. Practice the binary search boundary handling, since off-by-one on lo and hi is where people lose points.