Design an in-memory music analytics service: add_song, play_song(userId, songId), print_analytics() listing songs by number of unique listeners.
Asked in the phone screen stage. Implement music_analytics(commands), where commands are arrays: ["add_song", songId], ["play_song", userId, songId], or ["print_analytics"]. Return one analytics snapshot for each print command. Each snapshot lists [songId, uniqueListenerCount] pairs, ordered by descending listener count, then ascending songId. Duplicate songs are ignored, and plays for unknown songs are ignored.
Example: adding s1, then playing it by u1 twice produces [["s1", 1]]. With s2 played by two users, the output is [["s2", 2], ["s1", 1]].
def music_analytics(commands):