FastPrepTime Based Key-Value Store

Time Based Key-Value Store

Coalition logoCoalition● MediumFULLTIMEOA
Learn

Problem statement

Process set and get operations on a time-based key-value store. A get returns the value written for that key at the greatest timestamp not exceeding the query timestamp, or the empty string when none exists. Return "null" for set operations.

Function

runTimeMap(operations: String[], keys: String[], values: String[], timestamps: int[]) → String[]

Examples

Example 1

operations = ["set","get","get","set","get"]keys = ["foo","foo","foo","foo","foo"]values = ["bar","","","bar2",""]timestamps = [1,1,3,4,4]return = ["null","bar","bar","null","bar2"]

Each query sees the most recent value for foo at or before its timestamp.

Constraints

  • All four arrays have equal non-zero length.
  • Set timestamps for each key are strictly increasing.
  • There are at most 100000 operations.

More Coalition problems

See Coalition hiring insights
public String[] runTimeMap(String[] operations, String[] keys, String[] values, int[] timestamps) {
  // Write your code here.
}
operations["set","get","get","set","get"]
keys["foo","foo","foo","foo","foo"]
values["bar","","","bar2",""]
timestamps[1,1,3,4,4]
expected["null", "bar", "bar", "null", "bar2"]
Checking account…