Design Phone Directory
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A phone system owns the numbers 0 through maxNumbers - 1, all initially unassigned. Implement PhoneDirectory:
- get() assigns and returns the **smallest** unassigned number, or -1 if every number is taken.
- check(number) returns true if number is currently unassigned, false otherwise.
- release(number) makes number unassigned again. Releasing a number that is already unassigned does nothing.
Because get always hands out the smallest free number, the sequence of results is fully determined.
Examples
Constraints
- 1 <= maxNumbers <= 10^4
- 0 <= number < maxNumbers
- At most 2 * 10^4 calls in total
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.