Expiry · Easy
A cache maintenance endpoint receives entries with explicit expiry timestamps and a supplied clock. It must report expired keys without relying on system time.
Return expired keys in input order.
Input
Call
- Implement
solve(input)and return its result. Do not print fromsolve.
Input object
{ entries:{key:string,expiresAt:integer|null}[], now:integer }
Input rules
- Keys are unique. null means no expiry.
What each field means
entries— unique keys and theirexpiresAttimestamps;nullmeans no expiration.now— the supplied current timestamp. Do not read the system clock.
Output
Return value and rules
- Return keys whose non-null expiration time is at or before
now. - Preserve input entry order. Never include a non-expiring key.
- An expiration timestamp of
0is valid, not a missing value.
Constraints
- 0 <= entries.length <= 100000; timestamps and now in [0,1000000000000]
- Keys are nonempty ASCII strings up to 80 characters.
Examples
Example 1
{
"entries": [
{
"key": "a",
"expiresAt": 5
},
{
"key": "b",
"expiresAt": 6
},
{
"key": "c",
"expiresAt": null
}
],
"now": 5
}Returns
[
"a"
]Example 2
{
"entries": [],
"now": 0
}Returns
[]Required complexity
O(n) time and O(n) output space