Store Dispatch with Selector Subscriptions
Updated
Problem statement
Build a tiny state store with subscribers, like the store behind a frontend app. The state has 100 number fields, numbered 0 to 99, and every field starts at 0. Each subscriber picks some fields and watches their sum, which is its selected value. A subscriber is told about a dispatch only when its selected value changes.
Process the operations in order and return one list for each operation:
"subscribe"withargs[i] = [id, f1, f2, ...]: subscriberidstarts watching fieldsf1, f2, .... Return a list that holds its current selected value."unsubscribe"with[id]: subscriberidstops watching. Return an empty list."dispatch"with[f1, v1, f2, v2, ...]: set fieldf1tov1, fieldf2tov2, and so on, all at once. Return the ids of the current subscribers whose selected value after the dispatch differs from their selected value just before it, in the order they subscribed. Return an empty list if no selected value changed.
A subscriber that unsubscribes and later subscribes again counts as a new subscriber: its place in the order comes from its latest subscribe, and it may watch different fields.
Function
runStore(operations: String[], args: int[][]) → int[][]Examples
Example 1
operations = ["subscribe","subscribe","dispatch","dispatch","dispatch","subscribe","unsubscribe","dispatch"]args = [[1,0,1],[2,1],[0,5],[0,4,1,1],[1,1],[3,0],[1],[0,7]]return = [[0],[0],[1],[2],[],[4],[],[3]]Subscriber 1 watches fields 0 and 1, and subscriber 2 watches field 1; both start at 0. Setting field 0 to 5 changes only subscriber 1's sum (0 to 5). The next dispatch sets field 0 to 4 and field 1 to 1 together: subscriber 1's sum stays 4 + 1 = 5, so only subscriber 2 (0 to 1) is told. Setting field 1 to 1 again changes nothing. Subscriber 3 joins and sees field 0, which is 4. After subscriber 1 leaves, setting field 0 to 7 tells only subscriber 3.
Example 2
operations = ["subscribe","subscribe","dispatch","unsubscribe","subscribe","dispatch"]args = [[5,2],[3,2],[2,1],[5],[5,2,3],[2,9]]return = [[0],[0],[5,3],[],[1],[3,5]]Subscriber 5 joined before subscriber 3, so the first change lists 5 first. Subscriber 5 then leaves and joins again watching fields 2 and 3, which counts as a new, later subscription. So the last change lists 3 before 5.
Example 3
operations = ["subscribe","dispatch","dispatch"]args = [[8,0,1,2],[0,-3,1,3],[2,0]]return = [[0],[],[]]Fields 0 and 1 become -3 and 3 in one dispatch, so the sum stays 0 and nobody is told. Setting field 2 to the 0 it already holds changes nothing either.
Constraints
1 <= operations.length <= 1000andargs.length == operations.length- Each
operations[i]is"subscribe","unsubscribe"or"dispatch". - For
"subscribe",2 <= args[i].length <= 6: an id, then 1 to 5 different fields. For"unsubscribe",args[i].length == 1. For"dispatch",args[i].lengthis 2, 4, 6, 8 or 10, and the fields in it are all different. - Every id is between
1and10^6, every field is between0and99, and every value is between-10^6and10^6. "subscribe"uses an id that is not subscribed at that moment, and"unsubscribe"uses an id that is.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN
- LRU Key-Value Cache OperationsCohesity · PHONE SCREEN
- Fixed-Window Rate LimiterProofpoint · PHONE SCREEN
- LRU CacheApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
Interview reports that mention this question
Rippling interview experiences
- Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)