Show problems as
Classic problem #3005EasyArrayHash TableCounting

Count Elements With Maximum Frequency

Real-world version: Peak Locker Tally
Tracked in this browser only
Read Count Elements With Maximum Frequency on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A lost-property desk writes one ledger line for every item handed in, and each line records the number of the locker the item was stowed in. lockers[i] is the locker number written on line i, and the same locker number can appear on any number of lines.

Work out the largest number of lines any single locker number holds. Then add up the lines belonging to every locker number that holds exactly that many lines, and return that total.

Examples

Example 1

Input
lockers = [45, 78, 45, 91, 78, 12]
Output
4

Lockers 45 and 78 hold two lines each, while 91 and 12 hold one each, so two lockers tie at the top and they account for four lines between them.

Example 2

Input
lockers = [63, 27, 84, 19]
Output
4

Every locker number holds a single line, so all four numbers tie at the top and all four lines are counted.

Example 3

Input
lockers = [56, 56, 56, 31, 74, 31]
Output
3

Locker 56 holds three lines and no other number holds three, so only its three lines are counted.

Constraints

  • 1 <= lockers.length <= 100
  • 1 <= lockers[i] <= 100

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def peak_locker_lines(lockers: list[int]) -> int:
Java
public int peakLockerLines(int[] lockers)