Time Map with Sum and Average
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, using0when none exist.average: exact reduced fractionnumerator/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, oraverage. - 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.