Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started