Problem 391699 · easy · Phase 03 Linear Management & Searching

The One Missing Number

binary search · arrays

nums should contain every integer from start to start + len(nums) inclusive, in increasing order, but exactly one of them is missing. Return the missing integer.

Examples

Input:  start = 3, nums = [3, 4, 5, 7, 8]
Output: 6

Input:  start = 1, nums = [2, 3, 4]
Output: 1
Explanation: the range is 1..4 and 1 is absent.

Input:  start = 0, nums = [0, 1, 2]
Output: 3
Explanation: the range is 0..3; the last value is the one missing.

Constraints

  • 0 <= len(nums) <= 10**6
  • -10**9 <= start <= 10**9
  • O(log n) time is required; scanning for the gap is too slow on the largest tests.

Goals

  • Use the relationship between index and value to locate a gap
  • Handle the missing value being at either end of the range
Starting Python…