Question: Write a method whose signature - public int maxOccurrences(int[] a, int num) The method will receive as a parameter an array sorted in ascending order

Write a method whose signature - public int maxOccurrences(int[] a, int num) The method will receive as a parameter an array sorted in ascending order of integers, and an additional number num. The method will return how many times the number num appears in the array. For example, for the following array: a = {1, 1, 3, 6, 6, 6, 6, 8}, if num = 1 the method will return 2 (because 1 appears twice in the array). If num = 6 the method will return 4. If num = 10 the method will return 0 (because 10 does not appear at all in the array). The method you write should have the best runtime efficiency. A method that is not effective will not be awarded full points. B. (5%) What is the runtime efficiency of the method you wrote? Explain your answer.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!