Skip to main content
LeetCode 379, Medium. Topics: Design, Queue, Array, Hash Table, Linked List. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 13 parametrized pytest cases, and a playground notebook:

Problem

Design a phone directory that initially has maxNumbers empty slots that can store numbers. The directory should store numbers, check if a certain slot is empty or not, and empty a given slot. Implement the PhoneDirectory class:
  • PhoneDirectory(int maxNumbers) Initializes the phone directory with the number of available slots maxNumbers.
  • int get() Provides a number that is not assigned to anyone. Returns -1 if no number is available.
  • bool check(int number) Returns true if the slot number is available and false otherwise.
  • void release(int number) Recycles or releases the slot number.

Examples

Constraints

  • 1 <= maxNumbers <= 10^4
  • 0 <= number < maxNumbers
  • At most 2 * 10^4 calls will be made to get, check, and release.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026