Search
Jun 29, 2020
Given a sorted array A, write a code that finds all the indexes where the index is equal to the value of A[index].
Given a sorted array A, write a code that finds all the indexes where the index is equal to the value of A[index].
def sameIndexValue(myList):
res = []
for i in range(len(myList):
if i == myList[i]:
res.append(i)
return res
This works but can you find a more optimal solution? Try to use the fact that it is sorted.