Missing Number Finder
Given an array containing n distinct numbers taken from the range 0 to n, find the one number in the range that is missing from the array. For example, if n = 3 and the array is [3, 0, 1], the missing number would be 2.
[ [ 3, 0, 1 ] ]
Explanation. The number '2' is missing from the sequence 0 to 3.
[ [ 0, 1 ] ]
Explanation. The number '2' is missing from the sequence 0 to 2.
[ [ 9, 6, 4, 2, 3, 5, 7, 0, 1 ] ]
Explanation. The number '8' is missing from the sequence 0 to 9.
[ [ 0 ] ]
Explanation. The number '1' is missing from the sequence 0 to 1.
Follow-up: Can you solve the problem in linear time and constant space complexity?
The provided array will always have a length of at least 1 and at most 10,000. All elements of the array will be unique.
- Views
- 8