FastPrepGPU Credit Ledger with a Negative-Balance Failure State
Problems/GPU Credit Ledger with a Negative-Balance Failure State

GPU Credit Ledger with a Negative-Balance Failure State

OpenAI logoOpenAI● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

Process a time-aware GPU credit ledger from the operations in operations.

Supported operations

  • ADD grantId amount start expire: add a grant with positive credits. It is active when start <= timestamp < expire.
  • SUBTRACT amount timestamp: spend active credits, consuming grants with the earliest expiration first. Grants with equal expiration are consumed in insertion order.
  • BALANCE timestamp: append the active remaining balance as a decimal string.

Operation timestamps are nondecreasing. If a subtraction exceeds the active balance, the ledger enters a permanent negative-balance failure state. That subtraction does not need a returned value, and every later BALANCE appends NONE. Later additions or subtractions cannot recover the failed ledger.

Function

processGpuCreditsUntilNegative(operations: String[]) → String[]

Examples

Example 1

operations = ["ADD a 4 0 10","ADD b 3 0 5","SUBTRACT 5 1","BALANCE 1","BALANCE 6"]return = ["2","2"]

The subtraction consumes all three credits from b and two from a. The two remaining credits in a are active at both queried timestamps.

Example 2

operations = ["ADD a 2 0 10","SUBTRACT 3 1","BALANCE 1","ADD b 5 2 20","BALANCE 2"]return = ["NONE","NONE"]

The subtraction exceeds the two active credits and permanently fails the ledger, so both later balance queries return NONE.

Constraints

  • 1 <= operations.length <= 100000.
  • Grant identifiers are nonempty and unique.
  • 1 <= amount <= 10^9 and 0 <= start < expire <= 10^9.
  • Operation timestamps are nondecreasing.
  • All valid balances fit in a signed 64-bit integer.

More OpenAI problems

  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] processGpuCreditsUntilNegative(String[] operations) {
      // write your code here
    }

}
Checking account…