r/TechInterviewInsights • u/drCounterIntuitive • 5d ago
Interview Prep [OpenAI SWE Interview] Can You Solve This GPU Credit Calculator Coding Challenge?
Build an account balance tracker for GPU credits. Each credit grant has an amount, a start time, and a lifetime. Credits can be partially spent, and whatever remains disappears when the grant expires.
Support three operations: addCredit(creditID, amount, timestamp, expiration), useCredit(timestamp, amount), and getBalance(timestamp). The first two return nothing; getBalance returns the remaining usable credit at the requested time, including 0 when none remains.
For example:
addCredit("amazon", 40, 10, 50)
useCredit(30, 30)
getBalance(40) -> 10
addCredit("google", 20, 60, 10)
getBalance(60) -> 30
getBalance(61) -> 20
The first grant is usable from time 10 through time 60, inclusive. Spending 30 leaves 10. At time 60, that remaining 10 overlaps with the new 20-credit grant; at time 61, only the new grant remains.
If you'd like to attempt it without hints, try the full challenge here before revealing the considerations below.
Things to watch out for (click to reveal):
- Expiration boundaries: A grant is still usable at
timestamp + expiration, but not one time unit later. - Overspending: Spend as much as is available, ignore any unmet amount, and never let the balance go negative.
- Overlapping grants: Spend the earliest-expiring available grant first; break expiration ties by grant insertion order.
- Repeated labels: Reusing a
creditIDcreates a separate grant rather than replacing an earlier one.
Try the full GPU Credit Calculator coding challenge here.
Helpful resources for optimal interview prep:
- Need end-to-end expert guidance to land your next offer? Get interview-ready with a team of experienced Big Tech engineers (Meta, Google, Nvidia, Amazon, etc.) guiding you from wherever you are in your preparation journey until you're ready to clear the hiring bar. Through personalised roadmaps, diagnostic assessments, coaching, mock interviews, assigned tasks, regular check-ins, and progress tracking, we manage your preparation from start to finish and help determine when you're interview-ready. Explore Coditioning CoPilot.
- Preparing for the new AI-enabled coding interviews? Companies are increasingly introducing AI-enabled coding rounds that test how effectively you can use AI to solve real-world engineering problems, debug code, and build working solutions. Explore our AI-enabled interview preparation resources to understand these new formats and practise the skills they assess.
- Keep forgetting coding problems you've already solved? Classic DSA coding rounds haven't gone anywhere! If you've worked through Blind 75 or NeetCode 150 only to draw a blank on problems you've solved before and unfamiliar problems, try the Coditioning 300 neuro-optimised roadmap. It builds recall directly into your practice, so you retain what you learn effortlessly and gets you good at solving problems you haven't seen before
- Company-Specific Roadmaps: Explore interview preparation roadmaps for OpenAI, Anthropic, and other Big Tech companies.
- Company Question Banks: Practice real reported interview questions from OpenAI, Anthropic, Google, and other Big Tech companies. Updated regularly to give you the latest questions asked.
- 1-on-1 Mock Interviews & Free Consultation: Book a mock interview or free consultation with experienced Big Tech engineers.
- Everything you need to land your next tech offer: Visit Coditioning.com for everything you need to prepare for and land offers at Big Tech companies and AI labs.
- Looking for someone to practise with? Find a peer mock interview partner, study buddy, or accountability partner to practise interviews together, work through problems, and keep each other on track.
- Join our Discord Community (10,000+ members): Connect with other engineers, discuss interview preparation tips, recent interview experiences, get referrals, feedback on your CV and much more