Question: Write a function HowM any(A, x) where A is a sorted list of integers and x is an integer number. The function should return the
Write a function HowM any(A, x) where A is a sorted list of integers and x is an integer number. The function should return the number of elements of A that are equal x. For example if A = [1, 2, 4, 4, 4, 5, 15] and x = 4 then HowM any(A, x) should return 3. The runtime of the function should be O(log n)?
My current solution is O(n)
def HowMany(A,x): count = 0 for i in range(0,len(A)): if A[i] == x : count +=1 return count HowMany([1,2,2,2,3,2,4],2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
