Implement a Time-Based Key-Value Store

Quick Overview

Implement a time-indexed key-value store that sets values at timestamps and retrieves the most recent value at or before a query timestamp.

Implement a Time-Based Key-Value Store

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Implement a Time-Based Key-Value Store Implement `run_time_map(operations: list[list[str]]) -> list[str]`. The store begins empty. Apply operations in order: - `["set", key, value, timestamp]`: store `value` for `key` at the positive integer timestamp encoded as a decimal string. - `["get", key, timestamp]`: return the value stored for `key` at the greatest timestamp less than or equal to the query timestamp. Return the empty string if none exists. Return only the results of `get` operations, in operation order. Set timestamps for the same key are strictly increasing. ## Valid Input Domain - Keys and values are case-sensitive strings. - Timestamps are decimal encodings of positive signed 32-bit integers. ## Constraints - `0 <= operations.length <= 200,000` - Total key and value length is at most 2,000,000 characters. ## Public Examples ### Example 1 Input: `[["set", "foo", "bar", "1"], ["get", "foo", "1"], ["get", "foo", "3"], ["set", "foo", "baz", "4"], ["get", "foo", "4"], ["get", "foo", "5"]]` Output: `["bar", "bar", "baz", "baz"]` ### Example 2 Input: `[["get", "missing", "9"], ["set", "a", "x", "10"], ["get", "a", "2"]]` Output: `["", ""]` ```hint Search within one key's history Organize versions so a query can locate the rightmost timestamp that does not exceed its target. ```

Overview: Implement a time-indexed key-value store that sets values at timestamps and retrieves the most recent value at or before a query timestamp.

|Home/Coding & Algorithms/Oracle
Oracle logo
Oracle
Aug 14, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Implement a Time-Based Key-Value Store

Implement run_time_map(operations: list[list[str]]) -> list[str].

The store begins empty. Apply operations in order:

  • ["set", key, value, timestamp] : store value for key at the positive integer timestamp encoded as a decimal string.
  • ["get", key, timestamp] : return the value stored for key at the greatest timestamp less than or equal to the query timestamp. Return the empty string if none exists.

Return only the results of get operations, in operation order. Set timestamps for the same key are strictly increasing.

Valid Input Domain

  • Keys and values are case-sensitive strings.
  • Timestamps are decimal encodings of positive signed 32-bit integers.

Constraints

  • 0 <= operations.length <= 200,000
  • Total key and value length is at most 2,000,000 characters.

Public Examples

Example 1

Input: [["set", "foo", "bar", "1"], ["get", "foo", "1"], ["get", "foo", "3"], ["set", "foo", "baz", "4"], ["get", "foo", "4"], ["get", "foo", "5"]]

Output: ["bar", "bar", "baz", "baz"]

Example 2

Input: [["get", "missing", "9"], ["set", "a", "x", "10"], ["get", "a", "2"]]

Output: ["", ""]

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...