Schedule Multiple Software Timers
Updated
Problem statement
A device has one hardware timer but must support many logical software timers. Each request is [issuedAt, timerId, relativeTimeout] and schedules that timer to fire at issuedAt + relativeTimeout.
Scheduling an active timerId replaces its prior deadline. Before handling the first request at a timestamp, fire every timer whose deadline is at or before that timestamp. After all requests, fire every remaining timer. Return [fireTime, timerId] rows ordered by fire time and then timer ID.
Function
fireSoftwareTimers(requests: int[][]) → int[][]Examples
Example 1
requests = [[0,1,5],[1,2,2],[4,1,3]]return = [[3,2],[7,1]]Timer 2 fires at 3. Rescheduling timer 1 at time 4 invalidates its old deadline and moves it to 7.
Example 2
requests = [[0,2,4],[0,1,4],[4,3,1]]return = [[4,1],[4,2],[5,3]]Both due timers fire before the time-4 request, with the smaller timer ID first.
Constraints
1 <= requests.length <= 100000- Every request has exactly three integers.
0 <= issuedAt <= 10000000001 <= timerId <= 10000000001 <= relativeTimeout <= 1000000000- Request timestamps are nondecreasing, and every resulting fire time is at most
2000000000.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Score-Rotating Movie PlaylistNetflix · ONSITE INTERVIEWNetflix interview questions
- Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
- Expiring Key SetAmazon · ONSITE INTERVIEW
- Design Authentication ManagerOracle · ONSITE INTERVIEWOracle interview questions
- Delayed Job SchedulerWalmart Labs · ONSITE INTERVIEW
- Thread-Safe Task Storage and Worker DispatchNuro · ONSITE INTERVIEWNuro interview questions
- Notification Deduplication WindowGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Helpdesk Ticket ProcessingThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions