Question: In an array or list Z [] containing integers, an identity index is an index where A[i] = i, i.e. the value of the element

In an array or list Z [] containing integers, an identity index is an index where A[i] = i, i.e. the value of the element at that index equals the index itself. Write a method to return an identity index from a sorted list of distinct integers, if such an index exists, or -1 if it doesn't. Use time complexity O(logN) only. Use Python to solve this.

Example:

identityIndex([-5, -20, 0, 3, 4]) == 3, because Z[3] == 3 identityIndex([7, 4, 5, 7, 9]) == -1, because Z[2] == i isn't true for any i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!