Find missing value in sorted consecutive array
Company: Arista
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of array properties and algorithmic complexity, specifically detecting a single missing element in a sorted consecutive sequence within the Coding & Algorithms category.
Constraints
- nums is sorted ascending with distinct integers.
- At most one interior value is missing.
- Return None when no missing value is detectable.
Examples
Input: ([4,5,6,8,9],)
Expected Output: 7
Explanation: The first index whose value is offset too far reveals the missing number.
Input: ([-3,-2,-1,0,1],)
Expected Output: None
Explanation: A fully consecutive array returns None.
Input: ([10,11,12,13,15],)
Expected Output: 14
Explanation: The missing value is at the final gap.
Input: ([42],)
Expected Output: None
Explanation: A single observed value has no detectable missing interior value.
Hints
- For a perfect consecutive array, nums[i] - nums[0] equals i.
- Binary search for the first index where that invariant fails.