Throttled Updates with a Trailing Run
Updated
Problem statement
A throttled function runs at most once in any wait time units, however often it is called. This version does not lose the newest value: when calls come too soon, it holds back the latest one and runs it as soon as the waiting time is over.
Call i happens at time times[i] with value values[i]. Keep track of openAt, the earliest time the next run may start. Before the first run, a run may start at any time.
- A call at time
twitht >= openAtruns right away, at timet, with its own value. ThenopenAtbecomest + wait. - A call at time
twitht < openAtcannot run yet. It becomes the held call and replaces any call held before it. - When the time reaches
openAtand a call is held, the held call runs at timeopenAtwith its value. ThenopenAtgrows bywait.
A held run at time T happens before any call at time T. Calls at the same time are handled in the order they are given. After the last call, a call that is still held runs at openAt.
Return every run as a pair [time, value], in the order they happen.
Function
throttledUpdates(times: int[], values: int[], wait: int) → int[][]Examples
Example 1
times = [0,1,2,5,6,14]values = [1,2,3,4,5,6]wait = 4return = [[0,1],[4,3],[8,5],[14,6]]The call at 0 runs at once, and the next run may start at 4. The calls at 1 and 2 are too early. The call at 2 replaces the call at 1 as the held call. At time 4 the held value 3 runs, and the next run may start at 8. The calls at 5 and 6 are held, and 6 replaces 5. At time 8 the held value 5 runs, and the next start is 12. The call at 14 is after 12, so it runs at once.
Example 2
times = [0,1,3]values = [7,8,9]wait = 3return = [[0,7],[3,8],[6,9]]The call at 0 runs, and the next start is 3. The call at 1 is held. At time 3 the held value 8 runs first, so the next start moves to 6. That makes the call at 3 too early, so it is held and runs at 6.
Example 3
times = [5,5,5]values = [1,2,3]wait = 10return = [[5,1],[15,3]]Three calls at the same time. The first one runs at 5. The other two are too early, and the last one, value 3, is the one held. It runs at 5 + 10 = 15.
Constraints
1 <= times.length <= 1000andvalues.length == times.length0 <= times[i] <= 10^6, andtimesis sorted in non-decreasing order0 <= values[i] <= 10^41 <= wait <= 10^6
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
- Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Determine the Winner of Three-Card HandsOpenAI · PHONE SCREENOpenAI interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Asteroid CollisionSiemens · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI 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)