MediumNo. 2622
Cache With Time Limit — LeetCode 2622 Python Solution
- Topics
- JavaScript
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Write a class that allows getting and setting key-value pairs, however a time until expiration is associated with each key. The class has three public methods: set(key, value, duration): accepts an integer key, an integer value, and a duration in milliseconds.
Example
- Input
- actions = ["TimeLimitedCache", "set", "get", "count", "get"]
- Output
- [null, false, 42, 1, -1]
- Explanation
- At t=0, the cache is constructed.
Complexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
| 0194 | Transpose File | Medium |
| 0195 | Tenth Line | Easy |
| 0228 | Summary Ranges | Easy |
Frequently asked questions
- How hard is LeetCode 2622. Cache With Time Limit?
LeetCode 2622. Cache With Time Limit is rated Medium on LeetCode.
- What topics does LeetCode 2622. Cache With Time Limit cover?
LeetCode 2622. Cache With Time Limit is tagged JavaScript on LeetCode.