Data structures to manage available resources
Anonymous User
93

What is the best data structure for this case? Given N resources with ID from 0 to N-1, you can get a resource or free a resource.

We also need to consider the time & space complexity for get and free operations.

interface ResourcePool {
   int get();           // return an available ID
   void free(int id);   // mark ID as available 
}

There's two variants for this problem, based on whether free can free an already available resource.

Follow up: what if N is a super large number, say 1 billion or 1 trillion.

Comments (2)