I have a sorted list like nums = [-4,-1,0,3,10]
and I want to find the index of the first non-negative integer.
A linear time solution was provided to me:
def find(nums):
n = len(nums)
i = 0
while i < n and nums[i] < 0:
i += 1
return i
Is there a logarithmic solution to this question?
It is guaranteed that there will be a non-negative integer in the list.