Given an array , each element is one more or one less than its preceding element .find an element in it.(better than O(n) approach)
I have a solution for this but I have no way to tell formally if it is the correct solution:
Let us assume we have to find n.
- From the given index, find the distance to n; d = |a[0] - n|
- The desired element will be atleast
delements apart and jumpdelements - repeat above till
d= 0
[2,3,2,1,2,3,4]