Skip to content

Commit f455833

Browse files
committed
time based key value store- Stripe
1 parent 464fe0a commit f455833

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Solution/Day-097.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class TimeMap {
2+
public:
3+
/** Initialize your data structure here. */
4+
unordered_map<int , vector<pair<string , int>>>mp;
5+
TimeMap() {
6+
7+
}
8+
9+
void set(string key, string value, int timestamp) {
10+
mp[key].push_back(make_pair(value , timestamp));
11+
}
12+
13+
string get(string key, int timestamp) {
14+
const auto &v = mp[key];
15+
if(v.size()==0){
16+
return "";
17+
}
18+
auto c = upper_bound(v.begin() , v.end() ,
19+
[](int val , auto &p){
20+
return val < p.second;
21+
}
22+
);
23+
return c.second;
24+
}
25+
};
26+
27+
/**
28+
* Your TimeMap object will be instantiated and called as such:
29+
* TimeMap* obj = new TimeMap();
30+
* obj->set(key,value,timestamp);
31+
* string param_2 = obj->get(key,timestamp);
32+
*/
33+

0 commit comments

Comments
 (0)