LCC/Moose '20 Contest 1 J1 - Remembering Ratings

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Jerry has found a playlist with N songs! He decides to listen to each one and rate it on a scale from 1 to 5. He now wants to know the most frequent rating given to the songs in this playlist. If there are two ratings with the same frequency, he will choose the lower rating. Because there are a lot of songs in this playlist, can you help him find out what the most frequent rating is?

Input Specification

The first line will contain an integer N (1 \leq N \leq 10^5), the number of songs in this playlist. The next line will contain N integers, each between 1 to 5, inclusive, which is the rating that he gave that song.

Output Specification

Print out the rating that has the highest frequency, or the lowest rating if there is more than one rating with the highest.

Sample Input 1

6 
5 3 2 5 4 1

Sample Output 1

5

Sample Explanation 1

Out of the 6 total songs in the playlist, a rating of 5 was given to 2 songs, while the rest of the ratings were only given to 1 song each, so 5 is the most frequent rating given by Jerry in this playlist.

Sample Input 2

10
1 5 3 3 2 4 3 1 2 1

Sample Output 2

1

Sample Explanation 2

The most frequent ratings in this playlist are 1 and 3, both given to 3 songs each by Jerry. The answer is 1 since he will choose the lower rating if the highest frequency exists for multiple ratings.


Comments

There are no comments at the moment.