Problem · Design
GPU Credit Ledger
Learn this problemProblem statement
Implement a time-aware GPU credit ledger. Grants add credits for a bounded time interval, spending events consume active credits, and balance queries ask how many credits remain at a timestamp.
Supported operations
ADD grantId amount start expire: register a grant ofamountcredits. The grant is active for timestampsstart <= t < expire.SUBTRACT amount timestamp: consumeamountcredits active attimestamp. Consume credits from the grants that expire earliest. The consumption continues to affect later balances until those grants expire. Grants that begin after the subtraction timestamp cannot pay for it. If the active balance is insufficient, do not consume any credits.BALANCE timestamp: append the remaining active balance attimestampto the output.
Operations are registered in input order, but their timestamps do not have to be sorted. For events at the same timestamp, expiring grants are no longer active, new grants are active, and then subtraction events are applied in input order.
Function
processGpuCredits(operations: String[]) → String[]Examples
Example 1
operations = ["ADD a 4 20 60", "ADD b 3 30 40", "SUBTRACT 2 30", "BALANCE 30", "BALANCE 40"]return = ["5", "4"]At timestamp 30, both grants are active. The subtraction consumes two credits from grant b because it expires first, leaving a balance of five. At timestamp 40, grant b has expired and grant a still has all four credits.
More OpenAI problems
- Segmented Durable Key-Value StorePHONE SCREEN · Seen Jul 2026
- Durable String Key-Value StorePHONE SCREEN · Seen Jul 2026
- Prefix Matrix Products and AutogradPHONE SCREEN · Seen Jul 2026
- Streaming Entropy, Part 1: Batch EntropyPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Streaming Entropy, Part 2: Numerically Stable EntropyPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Streaming Entropy, Part 3: Block-wise EntropyPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Streaming Entropy, Part 4: Stable Streaming EntropyPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Memory AllocatorPHONE SCREEN · Seen Jul 2026