Logger with expiration time
Anonymous User
649

You are going to implement a hash class that has two functions, put and get.

void put(string key, int exp_time);
bool get(string key);

The put function will save key with expiration time exp_time.
The get function will return true if the key is already put and it's has not been expired. Also, let's assume that you have a function like get_time() that return current time.
Then, the follow up question is how to improve memory complexity. I think this is the difficult part of the problem. For the first part we can use a map of with values as expiration time. However, we need to throw away the keys that have already expired when put or get are called to save memory. Also, in calling put, the key can already be in the map and the new expiration time might be larger than or smaller than the previous one. Any suggestion on the followup question?

Comments (4)