All practice tasks

Coding (Algo)

Expired Cache Keys

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 from solve.

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 their expiresAt timestamps; null means 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 0 is 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

What this task practices

Expired Cache Keys is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.