Allocate and Release Amazon Connect Phone Numbers From a Pool
Last updated: November 29, 2026
Quick Overview
Design a pool of phone numbers 0 to n-1 with `get()` returning the smallest available number (or -1 if none), `check(num)` returning whether it is free, and `release(num)` returning a number to the pool.
Amazon
November 29, 20260
0
0 solved
Design a pool of phone numbers 0 to n-1 with `get()` returning the smallest available number (or -1 if none), `check(num)` returning whether it is free, and `release(num)` returning a number to the pool.
A screen question in Amazon's style, framed around a contact center product that hands out phone numbers to new agents and recycles them. It tests a clean free-set design, idempotent release, and the choice of a min-heap with lazy deletion when the smallest number must be returned.
What the Interviewer Expects
- Keeps an O(1) availability lookup
- Returns the smallest free number efficiently
- Makes release idempotent so double release cannot duplicate a number
- Explains lazy deletion and why it keeps operations logarithmic
- Mentions concurrency for a shared pool
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you allocate without the smallest-number requirement in O(1)?
- How would you make get and release safe with many concurrent callers?
- How would you add a cooldown so a released number is not reused for 24 hours?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Numbers are 0..n-1, all free initially. get returns the smallest free one and marks it taken. release of an already-free number is a no-op (important: a buggy client retrying a release must not ...
High-Level Design
A boolean array gives check. For smallest-first allocation, keep a min-heap of candidate free numbers. release pushes the number only when it was actually taken, so each number appears in t...