Skip to content

Instantly share code, notes, and snippets.

@rkpatel33
Last active August 29, 2015 14:14
Show Gist options
  • Save rkpatel33/b8556488ef226c4d9746 to your computer and use it in GitHub Desktop.
Save rkpatel33/b8556488ef226c4d9746 to your computer and use it in GitHub Desktop.
DocNav Phone Screen Part 1

DocNav Phone Screen

Part 1

You're running a pool of servers where the servers are numbered sequentially starting from 1. Over time, any given server might explode, in which case its server number is made available for reuse. When a new server is launched, it should be given the lowest available number.

Write a function which, given the list of currently allocated server numbers, returns the number of the next server to allocate.

For example:

>> next_server_number([5, 3, 1])
2

>> next_server_number([5, 4, 1, 2])
3

>> next_server_number([3, 2, 1])
4

>> next_server_number([2, 3])
1

>> next_server_number([])
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment