You are given a sorted array, say X [ ] where each element is unique. How best can you find an index say i such that element at that index is also i , i.e , X[i] = i .
We can find the index i with X[i] = i by modifying binary search. The algorithm works as :
Time complexity = \( O(logn) \), space complexity = \( O(1) \). public int findIndexEqualsValue (int[] array){ |