Coding Global Background
Coding Global

Array Index & Element Equality

Archiviert 3 years ago
1
6 Nachrichten
2 Mitglieder
3 years ago
In Discord öffnen
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

Array Index & Element Equality

Antworten (6)