Question: s Blue Main Page Problems Solve a Problem printRange 2 O maxCount Favorite Language/Type: Java ArraylntList implementing instance methods Related Links: ArraylntList.java Stuart Reges (on

 s Blue Main Page Problems Solve a Problem printRange 2 O

s Blue Main Page Problems Solve a Problem printRange 2 O maxCount Favorite Language/Type: Java ArraylntList implementing instance methods Related Links: ArraylntList.java Stuart Reges (on 2014/02/13) Author: Write a method maxCount that returns the number of occurrences of the most frequently occuring value in a sorted list of integers Because the list will be sorted, all duplicates will be grouped together, which will make it easier to count duplicates. For example suppose that a variable called list stores the following sequence of values: [1, 3, 4, 7, 7, 7, 7, 9, 9, 11, 13, 14, 14, 14, 16, 16, 18, 19, 19, 19] This list has values that occur just once (1, 3, 4, 11, 13, 18), values that occur twice (9, 16), values that occur three times (14, 19) and a single value that occurs four times (7). Thefore, the following call: list.maxCount() should return 4 to indicate that the most frequently occuring value occurs 4 times. It is possible that there will be a tie for the most frequently occurring value, but that doesn't affect the outcome because you are just returning the count, not the value. For example, if there are no duplicates in the list, then every value will occur exactly once and the maximum would be 1. If the list is empty, your method should return 0 You are writing a method for the ArraylntList class discussed in lecture (handouts 3, 5 and 6) public class ArrayIntList f private int[] elementData; // list of integers private int size; // current # of elements in the list ?methods You are not to call any other ArraylntList methods to solve this problem. Your solution must run in O(n) time. You may not use any auxiliary data structures to solve this problem, although you can have as many simple variables as you like. Remember that you can assume that the values appear in sorted (nondecreasing) order

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!