FastPrepTime Map with Sum and Average

Time Map with Sum and Average

Confluent logoConfluent● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Process operations on a time-indexed integer store. A set appends one value for a key at its timestamp. A query considers all values for that key whose stored timestamp is at most the query timestamp.

  • get: latest eligible value, or the empty string.
  • sum: sum of eligible values, using 0 when none exist.
  • average: exact reduced fraction numerator/denominator, or the empty string when none exist.

Each set returns null. Return one string result per operation.

Function

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

Examples

Example 1

operations = ["set","get","sum","average"]keys = ["a","a","a","a"]values = [4,0,0,0]timestamps = [1,1,1,1]return = ["null","4","4","4/1"]

The query uses exactly the stored prefix whose timestamps do not exceed its timestamp.

Example 2

operations = ["get","sum","average"]keys = ["x","x","x"]values = [0,0,0]timestamps = [5,5,5]return = ["","0",""]

The query uses exactly the stored prefix whose timestamps do not exceed its timestamp.

Example 3

operations = ["set","set","get","sum","average"]keys = ["a","a","a","a","a"]values = [2,4,0,0,0]timestamps = [1,3,2,3,3]return = ["null","null","2","6","3/1"]

The query uses exactly the stored prefix whose timestamps do not exceed its timestamp.

Constraints

  • 1 <= operations.length <= 100000, and all input arrays have equal length.
  • Operations are set, get, sum, or average.
  • For each key, set timestamps are strictly increasing.
  • -10^6 <= values[i] <= 10^6; aggregate sums fit signed 64-bit range.

Source note: Exact author-written prompt evidence retained from the latest verified source sighting.

More Confluent problems

See Confluent hiring insights
public String[] runTimeMapAggregates(String[] operations, String[] keys, int[] values, int[] timestamps) {
    // Write your code here.
}
operations["set","get","sum","average"]
keys["a","a","a","a"]
values[4,0,0,0]
timestamps[1,1,1,1]
expected["null", "4", "4", "4/1"]
Checking account…