FastPrepTime-Travel Key-Value Map with Deletions

Time-Travel Key-Value Map with Deletions

Stripe logoStripe● MediumINTERNONSITE INTERVIEW
Learn

Problem statement

Implement a key-value map that preserves historical state. Process the operations in order and return one string for every read operation.

  • PUT key timestamp value: record a new value for key at timestamp.
  • DELETE key timestamp: record that key is deleted from this timestamp onward, until a later PUT.
  • GET key timestamp: return the value from the latest PUT at or before timestamp, unless a later applicable DELETE hides it. Return the empty string when no value is visible.
  • GET_LATEST key: return the value visible after all events processed so far, or the empty string.

Timestamps on PUT and DELETE operations are strictly increasing. A GET may query any positive timestamp.

What the interview report shared

The source described normal map operations, timestamp-aware historical reads, deletion, and capturing the current time when a value is stored.

Function

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

Examples

Example 1

operations = ["PUT plan 1 basic", "PUT plan 4 pro", "GET plan 3", "GET plan 4", "DELETE plan 6", "GET_LATEST plan", "GET plan 5"]return = ["basic", "pro", "", "pro"]

At time 3, the latest value is basic. Time 4 sees pro. The deletion at time 6 makes the latest value empty, while a historical read at time 5 still returns pro.

Example 2

operations = ["PUT k 2 one", "DELETE k 5", "PUT k 8 two", "GET k 6", "GET k 8", "GET_LATEST k"]return = ["", "two", "two"]

The deletion hides the first value at time 6. A later put restores the key with value two.

Constraints

  • 1 <= operations.length <= 10^5.
  • Mutation timestamps are positive, strictly increasing 64-bit integers; query timestamps are arbitrary positive 64-bit integers.
  • Keys and values are non-empty strings without spaces.
  • For this exercise, assume historical reads use the latest event at or before the requested timestamp and deletion is represented by a timestamped tombstone.

More Stripe problems

See Stripe hiring insights
public String[] processTimeTravelMap(String[] operations) {
    // write your code here
}
operations["PUT plan 1 basic", "PUT plan 4 pro", "GET plan 3", "GET plan 4", "DELETE plan 6", "GET_LATEST plan", "GET plan 5"]
expected["basic", "pro", "", "pro"]
Checking account…