FastPrepLatest-Timestamp Key-Value Store
Problem · Hash Table

Latest-Timestamp Key-Value Store

MediumAmazon logoAmazonFULLTIMEPHONE SCREEN
See Amazon hiring insights

Problem statement

Implement a key-value store that chooses values by their supplied timestamps, not by arrival order. The four aligned arrays describe a finite sequence of operations:

  • operations[i] = 0: perform set(timestamps[i], keys[i], values[i]).
  • operations[i] = 1: perform get(keys[i]). Ignore timestamps[i] and values[i] for this operation.

A get returns the value from a preceding set for that key whose timestamp is greatest. If several preceding sets have that greatest timestamp, use the one that occurs latest in the operation sequence. If the key has never been set, return the empty string.

The problem statement continues
Pro

Examples

Example 1

operations = [0,0,1,0,1,0,1]keys = ["a","a","a","a","a","a","a"]values = ["newer","older","","tie","","newest",""]timestamps = [10,3,0,10,99,12,1]return = ["newer","tie","newest"]

The write at timestamp 3 does not replace timestamp 10. The later timestamp-10 write wins the tie. Timestamp 12 then becomes the greatest. Get timestamps are ignored.

FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week