Missing Number in a Sorted Range
Practice Missing Number in a Sorted Range for free on NudgeCode: Easy, Binary Search pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
nums has length n, is sorted in increasing order, and holds n of the n + 1 integers from 1 to n + 1, each at most once. Exactly one is missing. Return it in O(log n) time.
Example
nums = [1,2,3,5,6] -> 4
nums = [2,3,4] -> 1
nums = [1,2,3] -> 4
Constraints
- 0 <= nums.length <= 10^5
numsis strictly increasing
Similar to LC 268 (Missing Number), where the array is unsorted and the range starts at 0.