During a live stream, viewers post n hashtags (lowercase alphanumeric strings, no # symbol). Find the hashtag used most often. If two or more hashtags are tied for the highest frequency, output the one that comes first alphabetically (lexicographically smallest).
Line 1: an integer n.
Line 2: n space-separated hashtags.
A single hashtag: the most frequent one, with ties broken by lexicographically smallest.
Example 1
Input
6 python python java java go rust
Expected
java
Explanation
python and java both occur twice, tied for the highest frequency; go and rust occur once each. The tie-break picks the alphabetically smaller of python/java, which is java.
Example 2
Input
3 ai ai ml
Expected
ai
Explanation
ai occurs twice, more than ml's one occurrence, so ai wins outright.
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 →