A fuel app wants to remember how the petrol price of each city changed over time. For one key (a city), it must keep many values, each saved at its own time. Later, someone asks: what was the price at time t?
Write a class TimeMap with these calls:
TimeMap() starts an empty store.
void set(String key, String value, int timestamp) stores value for key at the time timestamp.
String get(String key, int timestamp) finds the value of key that was stored at the latest time not after timestamp, and returns it. If nothing was stored by then, return an empty string "".
Examples
Example 1:
Input
["TimeMap","set","set","get","get","get","set","get"]
[[],["mumbai","30",5],["mumbai","35",9],["mumbai",4],["mumbai",7],["mumbai",12],["delhi","28",13],["delhi",20]]
Output
[null,null,null,"","30","35",null,"28"]
Explanation
The price of mumbai is stored as "30" at time 5 and as "35" at time 9.
get(mumbai, 4): nothing was stored by time 4, so the answer is "".
get(mumbai, 7): the latest store by time 7 is "30".
get(mumbai, 12): the latest store by time 12 is "35".
Then delhi gets "28" at time 13, and get(delhi, 20) returns "28".