A radio station logs the track ID played during each rotation slot of the day, as a sequence of n integers in the order they aired. A track's play count is the number of slots in which that exact track ID appears in the log. Among all distinct track IDs that appear, one or more of them achieve the highest play count seen for any track in the log. Compute the sum of the play counts of exactly those tracks that achieve this maximum play count.
Line 1: an integer n.
Line 2: n integers id_1 ... id_n, the track ID played in each rotation slot.
Print a single integer: the sum of play counts over all track IDs whose play count equals the maximum play count in the log.
Example 1
Input
6 7 7 3 9 3 7
Expected
3
Explanation
Play counts: track 7 -> 3 plays, track 3 -> 2 plays, track 9 -> 1 play. The maximum play count is 3, achieved only by track 7, so the answer is 3.
Example 2
Input
5 5 5 6 6 7
Expected
4
Explanation
Play counts: track 5 -> 2 plays, track 6 -> 2 plays, track 7 -> 1 play. The maximum play count is 2, achieved by both track 5 and track 6, so the answer is 2 + 2 = 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →