As reported: Dropbox coding challenge on CodeSignal (2025): a four-level in-memory database where records are keyed by a unique string, each record maps field names to integers, and every operation carries a strictly increasing timestamp. Level 1 compare-and-set / compare-and-delete, level 2 scans, level 3 TTL, level 4 reading a value as of an earlier timestamp.
Implement an in-memory database. A record is identified by a string key and holds fields: string names mapped to integer values. Every operation has a timestamp; timestamps strictly increase from one operation to the next.
Level 1
SET timestamp key field value— set the field (creating the record if needed). Returns"".COMPARE_AND_SET timestamp key field expectedValue newValue— if the field exists and equalsexpectedValue, set it tonewValueand return"true"; otherwise change nothing and return"false".COMPARE_AND_DELETE timestamp key field expectedValue— if the field exists and equalsexpectedValue, delete it and return"true"; otherwise"false".GET timestamp key field— the field's value as a string, or""if it does not exist.
Level 2
SCAN timestamp key— all fields of the record, sorted by field name, as"field1(value1), field2(value2), …";""if there are none.SCAN_BY_PREFIX timestamp key prefix— the same, only fields whose name starts withprefix.
Level 3
SET_WITH_TTL timestamp key field value ttl— set the field so that it exists during[timestamp, timestamp + ttl)and then disappears. Returns"".COMPARE_AND_SET_WITH_TTL timestamp key field expectedValue newValue ttl— likeCOMPARE_AND_SET, and on success the field's lifetime becomes[timestamp, timestamp + ttl).
An expired field behaves exactly like a missing one in every operation.
Level 4
GET_WHEN timestamp key field atTimestamp— the field's value as it was at timeatTimestamp(≤ timestamp), or""if it did not exist then.atTimestamp = 0means "now", likeGET.
Example (levels 1–2)
SET 1 A B 4 → ""
SET 2 A C 6 → ""
COMPARE_AND_SET 3 A B 4 9 → "true"
COMPARE_AND_SET 4 A C 4 9 → "false"
COMPARE_AND_DELETE 5 A C 6 → "true"
GET 6 A C → ""
GET 7 A B → "9"
Example (level 3)
SET 1 A B 4 → ""
SET_WITH_TTL 2 X Y 5 15 → "" (exists until 17)
SET_WITH_TTL 4 A D 3 6 → "" (until 10)
COMPARE_AND_SET_WITH_TTL 6 A D 3 5 10 → "true" (D = 5 until 16)
GET 7 A D → "5"
SCAN 15 A → "B(4), D(5)"
SCAN 16 A → "B(4)"
Example (level 4)
SET_WITH_TTL 1 A B 3 10 → "" (until 11)
COMPARE_AND_SET_WITH_TTL 4 A B 3 7 9 → "true" (B = 7 until 13)
GET 10 A B → "7"
GET_WHEN 13 A B 3 → "3"
GET_WHEN 15 A B 13 → "" (expired at 13)
Constraints: at most 3·10^4 operations; timestamps are positive integers below 10^9, strictly increasing; keys, fields and prefixes are letters and digits; values are integers that fit in 64 bits; 1 ≤ ttl ≤ 10^6.
Code runner format: one operation per line, exactly as above. Implement solution(queries), where each query is a list of strings (["SET", "1", "A", "B", "4"]), returning one string per query; the harness prints each result in double quotes ("" for an empty string).
Clarifications
- The level 1 operations write values with no expiry: a plain
SETor a successful plainCOMPARE_AND_SETmakes the field permanent again. COMPARE_AND_SETandCOMPARE_AND_DELETEon a missing or expired field return"false".GET_WHENsees deletions and expirations: a field deleted (or expired) at or beforeatTimestampis""at that time.