Design a system that counts song upvotes and returns the top k most upvoted songs for a given artist.
Each song is identified by its songName together with its artistName. Different artists can have songs with the same name, and these are different songs.
The songs of an artist are ranked as follows:
songName comes first.SongVoteTracker(int k)
k is the maximum number of songs that getTopKSongs returns.void upvoteSongByOne(String songName, String artistName)
songName by the artist artistName.List<String> getTopKSongs(String artistName)
k songs of artistName, in ranking order.k upvoted songs, returns all of them in ranking order.artistName has been upvoted, returns an empty list.1 ≤ k ≤ 1001 ≤ songName.length(), artistName.length() ≤ 20songName and artistName contain only lowercase English letters.100,000 calls in total will be made to upvoteSongByOne and getTopKSongs.10,000 of these calls will be made to getTopKSongs.SongVoteTracker(k = 2)upvoteSongByOne(songName = "sunrise", artistName = "mira")upvoteSongByOne(songName = "ocean", artistName = "mira")getTopKSongs(artistName = "mira") returns ["ocean", "sunrise"]upvoteSongByOne(songName = "sunrise", artistName = "mira")upvoteSongByOne(songName = "lanterns", artistName = "mira")getTopKSongs(artistName = "mira") returns ["sunrise", "lanterns"]upvoteSongByOne(songName = "ocean", artistName = "mira")getTopKSongs(artistName = "mira") returns ["ocean", "sunrise"]getTopKSongs(artistName = "kabir") returns []
Explanation: At first, "ocean" and "sunrise" both have 1 vote, so the smaller name "ocean" comes first. Next, "sunrise" reaches 2 votes, while "lanterns" and "ocean" have 1 vote each. Only 2 songs are returned, so "lanterns" is picked over "ocean" because its name is smaller. Then "ocean" reaches 2 votes, ties with "sunrise" and comes first again. No song of "kabir" has been upvoted, so the last list is empty.
SongVoteTracker(k = 3)upvoteSongByOne(songName = "rain", artistName = "nora")upvoteSongByOne(songName = "rain", artistName = "nora")upvoteSongByOne(songName = "rain", artistName = "leo")upvoteSongByOne(songName = "home", artistName = "leo")upvoteSongByOne(songName = "home", artistName = "leo")getTopKSongs(artistName = "leo") returns ["home", "rain"]getTopKSongs(artistName = "nora") returns ["rain"]
Explanation: "rain" by "nora" has 2 votes, and "rain" by "leo" is a different song with 1 vote. "home" by "leo" has 2 votes, so it comes first. "leo" has only 2 upvoted songs, fewer than k = 3, so both are returned.