Song Play Analytics
Updated
Problem statement
Implement a small music analytics service. It stores songs, records users listening to songs, ranks songs by unique listeners, and tracks each user's recently played unique songs.
Operations
Process operations in order and return one row for each operation that produces output.
["ADD_SONG", songName]: Add a song and return its positive integer ID as a one-element row. IDs start at1and increase by1.["PLAY", songId, userId]: IfsongIdexists, record that the user played the song and produce no output. Otherwise, return a one-element row containingError: Song ID <songId> does not exist.and leave all analytics and recency state unchanged.["ANALYTICS"]: Return one row containing every song formatted assongName(uniqueListeners). Sort by unique-listener count descending, then song name lexicographically ascending.["RECENT", userId, k]: Return up tokdistinct song names most recently played by that user, newest first.
Repeated valid plays by the same user count once toward a song's unique-listener total. For RECENT, replaying a song moves it to the front rather than creating a duplicate. Invalid plays never affect either result.
Interviewer follow-ups
The base exercise adds songs, records plays, reports invalid song IDs, and prints analytics by unique listeners. Interviewers then ask candidates to return the last three, or more generally the last k, unique songs played by one user while preserving recency.
Function
runSongAnalytics(operations: String[][]) → String[][]Examples
Example 1
operations = [["ADD_SONG","Song A"],["ADD_SONG","Song B"],["ADD_SONG","Song C"],["PLAY","1","u1"],["PLAY","1","u2"],["PLAY","2","u1"],["PLAY","2","u1"],["PLAY","99","u3"],["ANALYTICS"],["RECENT","u1","3"]]return = [["1"],["2"],["3"],["Error: Song ID 99 does not exist."],["Song A(2)","Song B(1)","Song C(0)"],["Song B","Song A"]]Song A has two unique listeners. The invalid play of song 99 returns the required error and changes no state. User u1's repeated Song B play moves Song B to the front but does not duplicate it.
Constraints
- Song names are unique.
- Each
songIdandkis encoded as a base-10 integer string. - A
PLAYmay reference a song ID that has not been added; it must return the specified error row without changing state. 1 <= k <= 100000
More Rippling Onsite Interview questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Delivery Cost TrackerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Maximum Currency Conversion Along a Simple PathPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent WordsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Future-Effective Employee SalaryONSITE INTERVIEW · Seen Aug 2026
- Filter and Sort Scheduled TasksONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Build a Pivot Table with TotalsSigma Computing · PHONE SCREEN
- Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
- Structured Log Stream with QueriesOpenAI · PHONE SCREENOpenAI interview questions
- Banking System with Pending Transfer AcceptanceCircle · PHONE SCREENCircle interview questions
- Recent Metrics by Name and TagsVercel · PHONE SCREEN
- Streaming Top-K Frequent ElementsNVIDIA · PHONE SCREENNVIDIA interview questions
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Interview Slot BookingTrueFoundry · PHONE SCREEN
Interview reports that mention this question
- Rippling L7 and Senior Onsites: 18 Experiences (Part 7 of 12)
- Rippling Senior SWE Onsite Loops: 15 Experiences (Part 6 of 12)
- Rippling Staff and SDE-2 Onsites: 21 Experiences (Part 8 of 12)
- Rippling SDE-1 and SDE-2 Onsites: 14 Experiences (Part 9 of 12)
- Rippling SWE Loops and History: 23 Experiences (Part 10 of 12)
- Rippling KV and Music Screens: 33 Experiences (Part 4 of 12)