Search
⌘K

Leetcode 2622. Cache With Time Limit

Design a time-limited key-value store with set(key, value, duration) that returns true if it overwrote an unexpired key (false otherwise), get(key) returning the value or -1 if expired, and count() returning the number of unexpired keys. The core challenge is efficiently tracking per-key expiry times and handling expirations (e.g., via timestamped hashmap with lazy cleanup or a min-heap) so get/count operations reflect only unexpired entries.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.