Cache With Time Limit — LeetCode 2622 Python Solution
MediumJavaScript
- Problem
- #2622
- 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
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
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.