logo Practice-It logo

maxCount

Related Links:
Author: Marty Stepp

Write a method maxCount that returns the number of occurrences of the most frequently occurring 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). Therefore, the call of list.maxCount() should return 4 to indicate that the most frequently occurring 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.

Assume you are adding to the ArrayIntList class with following fields:

public class ArrayIntList {
    private int[] elementData;
    private int size;

    // your code goes here
}
Type your solution here:


This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.