Credits You're building a system to track balances for the OpenAl API credit purchasing system. API users can purchase credit grants, specified by an ID, that are active at a timestamp and that let them use the API. Unused credit grant balances expire at a certain time. However, there's a kink in our system: requests can arrive out of order because our system is built on a really unstable network. For example, a request to subtract credits can arrive at the system before the request to add credits, even though the request to add credits has a lower timestamp. Your task is to implement the Credits class, which should support the following operations: • Granting credits, subtracting credits, and getting the credit balance for a user • The ability to handle requests that arrive out of order Some guidelines/hints: • Do NOT worry about memory or performance concerns. Write simple, working code. No fancy data structures are needed here. timestamp). • Subtract from grants expiring soonest first. • All timestamps can be represented as ints for simplicity and are unique (no two actions will happen at the same
CodingSenior
Design a credit tracking service for user token balances
Design a system that tracks user token credits and can efficiently query the number of tokens a user has at any given timestamp. The service should handle credit additions, deductions, and historical balance lookups.
Contextos reais
Onde essa pergunta já apareceu
Use esses exemplos para entender em que contexto ela costuma cair e adaptar sua prática.
OpenAIseniormar. de 2026
Anexos públicos
Materiais associados
Nenhum anexo público associado a esta pergunta.
Próximo passo
Depois de treinar essa pergunta, vale abrir outras do mesmo tipo e da mesma senioridade para comparar padrões de resposta.
Isso ajuda a sair da memorização de uma resposta só e entrar em repertório real de entrevista.
Continue a preparação com o banco completo
No app você encontra perguntas parecidas, compara empresas e aprofunda essa busca com mais filtros.