Does anyone know a faster-than-linear algorithm for finding a duplicate in a sequential list of numbers? I'm working in Java now but any language or psuedo-code is fine.
For example, given this int[] input:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7 | 8 | 9
Output would be either index or value '7'.
I know the obvious traversal at O(n)
linear time, but I'm trying to see if this is possible via binary search at O(log n)
time.