I have a list, A, of integers of such that:
- len(A) ≥ 2
- The first and last elements of A have different signs
- All the elements of A are non-zero
I need to write a function that detects the first sign change beside the first and last elements and where O(log n). Is it possible?
def myFunction(A,begin):
if(begin >= len(A)):
return [A[0],A[len(A)-1]]
if(A[begin]>0):
if(A[begin+1]>0):
return myFunction(A,begin+1)
else:
return [A[begin],A[begin+1]]
else:
if (A[begin + 1] < 0):
return myFunction(A, begin + 1)
else:
return [A[begin], A[begin + 1]]