Song Play Analytics
Reported by candidates from Rippling's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Rippling OA reported in November 2025 looks like a product spec, but it's really a design problem: three hash maps and one ordered structure per user. Song Play Analytics asks you to add songs, record plays, rank by unique listeners, and return a user's last k unique songs. Nothing here is hard algorithmically. The risk is a sloppy state update on an invalid play, or a recency list that duplicates songs. If you blank on the structure under the clock, StealthCoder is the invisible safety net that reads the prompt and hands you a working layout.
The problem
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 at 1 and increase by 1. ["PLAY", songId, userId]: If songId exists, record that the user played the song and produce no output. Otherwise, return a one-element row containing Error: Song ID <songId> does not exist. and leave all analytics and recency state unchanged. ["ANALYTICS"]: Return one row containing every song formatted as songName(uniqueListeners). Sort by unique-listener count descending, then song name lexicographically ascending. ["RECENT", userId, k]: Return up to k distinct 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 songId and k is encoded as a base-10 integer string. A PLAY may reference a song ID that has not been added; it must return the specified error row without changing state. 1 <= k <= 100000
Reported by candidates. Source: FastPrep
Pattern and pitfall
Here's what it reduces to. Keep a songs map from id to name, a listeners map from id to a set of users, and per user an ordered map or a linked-hash structure of song ids. On PLAY, check the id first. If it's missing, emit the error row and touch nothing. Otherwise add the user to the set and move the song to the front of that user's recency order: delete it if present, then reinsert it. ANALYTICS sorts every song by unique count descending, then name ascending, and formats each as name(count). Songs with zero listeners still appear. RECENT walks the order newest first and stops at k or the end. The common pitfalls are counting repeat plays twice, duplicating songs in recency, and mutating state before validating the id. If you freeze mid-assessment, StealthCoder is the hedge that gets the structure on screen.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Song Play Analytics cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Rippling's OA.
Rippling reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Song Play Analytics FAQ
How hard is the Rippling Song Play Analytics question really?+
Easy to medium. There's no clever algorithm. It's a design and bookkeeping exercise with a few edge cases. Candidates lose points on invalid plays mutating state, duplicate recency entries, and tie-break sorting, not on complexity.
What's the trick to the RECENT operation?+
Keep per-user recency in an insertion-ordered structure. On each valid play, remove the song if it's already there, then append it as newest. To answer RECENT, read from the newest end up to k items. That gives move-to-front without duplicates.
How do I count unique listeners correctly?+
Store a set of user ids per song. Adding the same user twice changes nothing, so repeated plays count once. The count is just the set size. Don't keep a running integer, since it will drift on repeats.
What edge cases should I test before submitting?+
Test a PLAY with a nonexistent song id and confirm nothing changes. Test songs with zero listeners still showing as name(0). Test ties sorted by name ascending. Test k larger than the user's history, and a user who never played anything.
How do I prepare for this in 48 hours?+
Practice writing a small class with hash maps and sets that processes a list of command arrays. Focus on parsing string arguments to ints, validating before mutating, and a custom sort with two keys. Then run the sample by hand once.