All problems
0491EasyArrayHash TableCounting

Peak Locker Tally

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3005Count Elements With Maximum Frequency

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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