AO
Back

Credit Tracker with Expiring Credits

Phone ScreenPhone ScreenLast reported August 2025Low Frequency

Problem Overview

Part 1 — Credits with expiry, spent earliest-expiring first

Perplexity's credit tracker, from one first-hand report (August 2025). The post body does not name the round; only its title says phone screen. It gives no outcome. This is everything it says about the problem:

Design a CreditTracker class with 3 methods: 1. def add_credit(start_time, end_time, credit) 2. def subtract_credit(time, credit) 3. def check_credit(time) When you subtract credit, you want to subtract the one with earliest expiration time. There is no guarantee that the time in add_credit and subtract_credit will be in increasing order.

Where the other rules come from. A commenter on the only Perplexity report asked whether this is the same as OpenAI's GPU-credit question; the rules below follow the OpenAI reports — confirm with your interviewer. We have many first-hand reports of the OpenAI question; nobody in them mentions Perplexity, and the Perplexity post itself does not say it is the same question.

Implement CreditTracker() with:

  • add_credit(start_time, end_time, credit): grant credit usable from start_time until end_time.
  • subtract_credit(time, credit): spend credit at time. The tests ignore what it returns.
  • check_credit(time): return the credit usable at time, as an int; 0 when nothing is usable.

Graded rules:

  • From the Perplexity report: a spend takes from the credit with the earliest expiration time first, then the next earliest.
  • From the Perplexity report: the times in add_credit and subtract_credit can arrive in any order.
  • From the OpenAI reports: a spend can only use credit valid at its own time. A grant that has expired by then, or has not started yet, does not pay for it, even if it expires earliest.
  • From the OpenAI reports: a grant added after a spend was called can still pay for it, if it is valid at the spend's time. The answers are the same as if every call had arrived in time order.
  • From the OpenAI reports: what a spend takes is gone for every later time, and check_credit(time) counts only the spends that have happened by time. A query earlier than a spend is not reduced by it.

Not graded: the OpenAI reports disagree, so ask your interviewer

  • Is a grant still usable at exactly end_time? Most OpenAI reports say no; one says yes. The tests never query or spend exactly at a start or end time.
  • What if a spend needs more credit than is valid at its time? OpenAI reports variously say the balance query returns None from then on, throws an exception, or that the tests never let it happen. The tests never overspend.
  • The OpenAI interface differs: several OpenAI variants give grants an id, the methods are named differently (add, subtract or charge, get_balance), and the argument order varies. The tests use the Perplexity names above.

Our setup — ask your interviewer

Integer times; check_credit returns 0 when nothing is valid; two grants that expire at the same time may be drained in either order (the tests' answers do not depend on it). Our reference counts a grant valid for start_time <= t < end_time and returns None after a spend it cannot cover, but neither choice is graded.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 4
Trade-off discussion

Which grant does a spend draw from first?

Probes for: subtract_credit — the report: the one with the earliest expiration time; per the OpenAI reports it must also be valid at the spend's time

What if a grant arrives after a spend at a later time?

Probes for: the report says the times are not guaranteed to increase — record the calls and compute at query time

Is a grant usable at exactly end_time, and what happens when a spend needs more than is valid?

Probes for: clarifying — not in the Perplexity report; the OpenAI reports disagree, so ask

How would you avoid replaying every call on each check_credit?

Probes for: optimization — our analysis; the most reported follow-up in the OpenAI version

What Reports Emphasize

What the one Perplexity report says: one class with three methods; a spend takes from the credit with the earliest expiration time first; the times in add_credit and subtract_credit are not guaranteed to arrive in increasing order. The post records no outcome, test cases or follow-ups. The post body does not name the round; only its title says phone screen.

From the OpenAI GPU-credit reports (a commenter on the Perplexity report asked whether this is the same question; confirm with your interviewer): candidates who assumed the calls arrive in time order struggled, and recording the calls and computing at query time works; an expired grant cannot pay for a spend; one candidate found the earliest-expiring rule only in the last two test cases, as a requirement nobody had mentioned; candidates advise reading every test case before designing.

Ask: whether a grant is usable at exactly its end_time, and what happens when a spend needs more credit than is valid at its time. The OpenAI reports disagree on both.

Practice

Write your own against 10 test cases, or read the worked solution — approach, complexity, and code that runs.
Perplexity · Phone Screen · Reported 1× across candidate reports
Is this helpful?