FastPrepTTL Cache Operations
Problems/TTL Cache Operations

TTL Cache Operations

Oracle logoOracle● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report identifies this task and its central operation. This practice version states the deterministic interface, boundary behavior, and ordering rules needed for consistent execution while preserving the reported capability.

Implement a key-value cache where each entry has its own TTL.

Support the following operations:

  • SET <key> <value> <ttlSeconds> <now>
  • GET <key> <now>
  • CLEANUP <now>

GET is the hot path, so it should not scan the whole cache to remove expired entries. A separate sidecar or background process may perform proactive cleanup.

Return the output lines produced by the operation batch. GET should print the current value or NULL if the key is missing or expired.

Function

runTimedCache(operations: String[]) → String[]

Complete the function runTimedCache in the editor below.

runTimedCache has the following parameter:

  1. String[] operations: cache operations executed in order

Returns String[]: the output lines produced by the batch.

Examples

Example 1

operations = ["SET a 1 5 0", "GET a 3", "GET a 6"]return = ["1", "NULL"]

Key a expires at time 5. It is still valid at time 3 and expired by time 6.

Example 2

operations = ["SET a 1 5 0", "SET b 2 2 0", "CLEANUP 3", "GET a 3", "GET b 3"]return = ["1", "NULL"]

By time 3, key b has expired and may be removed during cleanup. Key a is still alive.

Constraints

  • GET should stay cheap even when the cache is large.
  • Each key has a per-item TTL.
  • A cleanup helper may delete expired entries outside the hot path.

More Oracle problems

  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public String[] runTimedCache(String[] operations) {
        // write your code here
    }

}
Checking account…