Most Requested Song
Easy · hash map
A radio station writes down every song request it receives, in the order the calls came in. You are given the list requests, where each item is the title of one requested song.
Return the title that was requested the most times.
If several titles are tied for the most requests, return the one that was requested first, meaning the tied title whose earliest request comes earliest in the list.
Examples
Example 1
Input: requests = ["rock", "pop", "rock", "jazz", "pop", "rock"]
Output: "rock"
rock was requested three times, pop twice and jazz once.
Example 2
Input: requests = ["jazz", "pop", "pop", "jazz"]
Output: "jazz"
jazz and pop are tied on two requests each. jazz was requested first, so it wins the tie.
Example 3
Input: requests = ["blues"]
Output: "blues"
Constraints
- 1 <= len(requests) <= 2000
- Each title has between 1 and 20 characters, all lower-case letters or digits.