bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
MediumArrays & HashingLC 379

Design Phone Directory

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.

Asked at 3 companies
DropboxGoogleMicrosoft
Hints
  • 1.Think about which data structure fits best
  • 2.Consider the time complexity of your approach
  • 3.Look for patterns in the constraints
LeetCode