Skip to content

Commit 4fdaf4e

Browse files
committed
#981: description update
1 parent f507110 commit 4fdaf4e

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

c-sharp/Problems/binary-search/TimeBasedKeyValueStore.cs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,45 @@
22
* 981
33
* Time Based Key-Value Store
44
**
5-
* Design a time-based key-value data structure that
6-
* can store multiple values for the same key at different time stamps
7-
* and retrieve the key's value at a certain timestamp.
5+
* Design a time-based key-value data structure that can store multiple values
6+
* for the same key at different time stamps and retrieve the key's value at a certain timestamp.
87
*
98
* Implement the TimeMap class:
10-
* TimeMap() Initializes the object of the data structure.
9+
* TimeMap() Initializes the object of the data structure.
1110
*
12-
* void set(String key, String value, int timestamp) Stores the key key with the value value at the given time timestamp.
11+
* • void set(String key, String value, int timestamp)
12+
* Stores the key key with the value value at the given time timestamp.
1313
*
14-
* String get(String key, int timestamp) Returns a value such that set was called previously, with timestamp_prev <= timestamp.
15-
* If there are multiple such values, it returns the value associated with the largest timestamp_prev.
14+
* • String get(String key, int timestamp)
15+
* Returns a value such that set was called previously,
16+
* with timestamp_prev <= timestamp.
17+
* If there are multiple such values,
18+
* it returns the value associated with the largest timestamp_prev.
1619
* If there are no values, it returns "".
20+
*
21+
* Example 1:
22+
* Input
23+
* ["TimeMap", "set", "get", "get", "set", "get", "get"]
24+
* [[], ["foo", "bar", 1], ["foo", 1], ["foo", 3], ["foo", "bar2", 4], ["foo", 4], ["foo", 5]]
25+
*
26+
* Output
27+
* [null, null, "bar", "bar", null, "bar2", "bar2"]
28+
*
29+
* Explanation
30+
* TimeMap timeMap = new TimeMap();
31+
* timeMap.set("foo", "bar", 1); // store the key "foo" and value "bar" along with timestamp = 1.
32+
* timeMap.get("foo", 1); // return "bar"
33+
* timeMap.get("foo", 3); // return "bar", since there is no value corresponding to foo at timestamp 3 and timestamp 2, then the only value is at timestamp 1 is "bar".
34+
* timeMap.set("foo", "bar2", 4); // store the key "foo" and value "bar2" along with timestamp = 4.
35+
* timeMap.get("foo", 4); // return "bar2"
36+
* timeMap.get("foo", 5); // return "bar2"
37+
*
38+
* Constraints:
39+
* • 1 <= key.length, value.length <= 100
40+
* • key and value consist of lowercase English letters and digits.
41+
* • 1 <= timestamp <= 10^7
42+
* • All the timestamps timestamp of set are strictly increasing.
43+
* • At most 2 * 10^5 calls will be made to set and get.
1744
**
1845
* https://leetcode.com/problems/time-based-key-value-store/
1946
***/

0 commit comments

Comments
 (0)