As reported: Opendoor senior full-stack (Seattle, 2026), technical screen. Part 1: build a key-value store supporting add, update and delete. Part 2: add
isExpired,sleep(time)andsetTTL(ttl).
Implement an in-memory KeyValueStore with string keys and values. Time is virtual: it starts at 0 and only moves when sleep is called.
Part 1
add(key, value)— store the pair ifkeyis not present; returntrue. Ifkeyis already present, change nothing and returnfalse.get(key)— return the value, or""ifkeyis not present.update(key, value)— replace the value of a present key and returntrue; returnfalseifkeyis not present.remove(key)— delete a present key and returntrue; returnfalseif it is not present. (This is the "delete" operation; it is namedremovebecausedeleteis a keyword in C++.)
Part 2
setTTL(ttl)— keys written (added or updated) from now on expirettltime units after that write.ttl = 0means they never expire. Keys written earlier keep the expiry they were given. At the start the TTL is 0.sleep(time)— move the clock forward bytimeunits.isExpired(key)—trueifkeywas written, not removed, and its expiry time has been reached (a key written at timetwith TTLTis live whilenow < t + T);falseif it is live or not stored at all.
An expired key counts as not present for add, get, update and remove; adding it again stores it fresh.
Example
setTTL(10)
add("x", "1") -> true written at 0, expires at 10
sleep(4)
update("x", "2") -> true written at 4, now expires at 14
sleep(8) now = 12
isExpired("x") -> false
get("x") -> "2"
sleep(2) now = 14
isExpired("x") -> true
get("x") -> ""
update("x", "3") -> false expired keys are not present
add("x", "4") -> true stored again, expires at 24
isExpired("x") -> false
Constraints: at most 10^4 calls; 0 ≤ ttl, time ≤ 10^6; keys and values are short strings.
Code runner format: two lines in LeetCode's design format: the list of operations (starting with "KeyValueStore") and the list of argument lists. The harness prints the list of results, with null for the constructor, setTTL and sleep.