Stripe Interview Question

Create a ServerManager class with the functions allocate(string) and deallocate(string) to the following specifications: allocate('apibox') = 'apibox1' allocate('apibox') = 'apibox2' allocate('sitebox') = 'sitebox1' allocate('apibox') = 'apibox3' deallocate('apibox2') allocate('apibox') = 'apibox2'

Interview Answer

Anonymous

Sep 18, 2017

Use a map> where the key is the string you are allocating, and the value if a vector of allocations of that string. O(1) for insertion in all cases, O(1) for reading/deleting

1