array says X
which is sorted and has duplicates. How best can you find an index say i
such that element at that index is also i
. That is X[i] = i
.
Its a famous question when duplicaes are not present
When duplicates are present for say
-100,0,1,3,3,3,3,3,3
here it becomes difficult to do binary search on ( X[i] - i ==0 )