Single Missing Number
Last updated
Last updated
Given a contiguous sequence of numbers in which each number repeats thrice, there is exactly one missing number. Find the missing number.
The Idea: Because we know that the sequence of numbers are integer continuous, we can model what we expect for the output with the function , shown below in blue. Then we can perform a binary search to find the missing number. If the middle element is what we expect, then either the missing number exists to the right of it, or the middle element is the missing number. In the case that it is the missing number, the next iteration of binary search will search left to find it.
Complexity: O(logn) time and space