Skip to content

Instantly share code, notes, and snippets.

@rkpatel33
Last active June 13, 2022 23:12
Show Gist options
  • Save rkpatel33/e8ce40296f30b24ac641 to your computer and use it in GitHub Desktop.
Save rkpatel33/e8ce40296f30b24ac641 to your computer and use it in GitHub Desktop.
DocNav Phone Screen Part 2

DocNav Phone Screen

Part 2

Server names consist of an alphabetic host type (e.g. "apibox") concatenated with the server number, with server numbers allocated as before (so "apibox1", "apibox2", etc. are valid hostnames).

Write a name tracking class with two operations, allocate(host_type) and deallocate(hostname). The former should reserve and return the next available hostname, while the latter should release that hostname back into the pool.

For example:

>> tracker = Tracker.new

>> tracker.allocate('apibox')
"apibox1"

>> tracker.allocate('apibox')
"apibox2"

>> tracker.deallocate('apibox1')
nil

>> tracker.allocate('apibox')
"apibox1"

>> tracker.allocate('sitebox')
"sitebox1"
@eliezergyan
Copy link

How do I implement this is JavaScript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment