Array Index & Element Equality
Archiviert 3 years ago
H
horang
Given a sorted array arr of distinct integers, write a function indexEqualsValueSearch that returns the lowest index i for which arr[i] == i. Return -1 if there is no such index. Analyze the time and space complexities of your solution and explain its correctness.
```input: arr = [-8,0,2,5]
output: 2 # since arr[2] == 2
input: arr = [-1,0,3,6]
output: -1 # since no index in arr satisfies arr[i] == i.```
[time limit] 5000ms
[input] array.integer arr1 ≤ arr.length ≤ 100
[output] integer

