Problem, as an interviewer would state it:
"Build a minimal in-memory key-value store supporting set(key, value, ttlMs), get(key), and delete(key) — a key should genuinely become inaccessible once its TTL expires, like a simplified real Redis."
Examples:
store.set("session:1", "alice", 5000);
store.get("session:1"); // "alice" -- before 5s
// ... after 5s ...
store.get("session:1"); // undefined -- genuinely expired
Clarifying questions expected:
- Should expiry be checked LAZILY (only on access) or actively (a background sweep on a timer)?
- What happens to a key with NO TTL specified — does it expire eventually, or persist forever?
- Should a genuinely expired entry be removed from internal storage immediately, or just made inaccessible?
Code / implementation expected: Yes — real, direct proof with a real, measured 50ms TTL: the value present before expiry, genuinely gone after, with the internal store confirmed to self-clean the expired entry.