Let A be a sorted array containing n distinct positive integers. Let x be a positive integer such that both x and 2x are not in A.
Describe an efficient algorithm to find the number of integers in A that are larger than x and smaller than 2x
what is the complexity of the algorithm? can someone write a pseudo code without using libraries?
I know this can be done with a linear time complexity but binary search could be modify to achieve this. The following is the linear time complexity solution I came up with
def find_integers(A, x):
integers = 0
for element in A:
if element > x and element < 2*x:
integers += 1
return integers