Skip to main content
All Questions

Design a token grant system with automatic one-hour release.

Unlock detailed company stats for this questionUpgrade

A bucket holds a limited number of tokens. Users request tokens and are either granted or rejected based on current availability. If granted, the user holds those n tokens for exactly 1 hour, after which they are automatically returned to the bucket. Support requestTokens(userId, n), releaseTokens(userId), and a background expiry mechanism.

Discussion points: a min-heap / priority queue ordered by expiry time for auto-release; handling concurrent requests (locking vs. atomic operations); edge cases such as partial grants, a user requesting tokens they already hold, and expiry during an active request; time complexity of grant and release.

Expect follow-ups like

  • How do you handle concurrent requests?
  • What edge cases exist such as partial grants or expiry during a request?

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.