From 0dbd75e52b3598c514f9eb51d267ed916f724be8 Mon Sep 17 00:00:00 2001 From: Trent Andraka Date: Sun, 21 Oct 2018 04:48:12 -0500 Subject: [PATCH] Create allocate_servers.txt #165 Example of a good interview problem --- ASSIGNMENTS/allocate_servers.txt | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ASSIGNMENTS/allocate_servers.txt diff --git a/ASSIGNMENTS/allocate_servers.txt b/ASSIGNMENTS/allocate_servers.txt new file mode 100644 index 00000000..ccd8c344 --- /dev/null +++ b/ASSIGNMENTS/allocate_servers.txt @@ -0,0 +1,35 @@ +# 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. In addition, you should demonstrate your approach to testing that your function is correct. You may choose to use an existing testing library for your language if you choose, or you may write your own process if you prefer. + +# For example, your function should behave something like the following: + +# >> 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 + + +# 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() +# >> tracker.allocate("apibox") +# "apibox1" +# >> tracker.allocate("apibox") +# "apibox2" +# >> tracker.deallocate("apibox1") +# nil +# >> tracker.allocate("apibox") +# "apibox1" +# >> tracker.allocate("sitebox") +# "sitebox1