Problem · Array
Chronological Sliding-Window Request Counter
Learn this problemProblem statement
Process chronological operations describing request arrivals and count queries.
["ADD", t]records one request at integer timestampt.["COUNT", t, n]asks how many priorADDtimestamps lie in the inclusive interval[t - 60 * n, t].
Operation timestamps are nondecreasing. Return one integer for each COUNT, in operation order. A request exactly at either boundary is included.
Function
processRequestOperations(operations: String[][]) → int[]Examples
Example 1
operations = [["ADD","10"],["ADD","70"],["COUNT","70","1"],["COUNT","71","1"]]return = [2,1]The first query includes timestamps 10 and 70. The second window starts at 11, excluding timestamp 10.
Example 2
operations = [["COUNT","0","5"],["ADD","0"],["COUNT","0","1"]]return = [0,1]The first query has no prior requests; the second includes the request at its upper boundary.
Constraints
1 <= operations.length <= 200000.0 <= t <= 1000000000.1 <= n <= 1000000000.- All rows are valid and timestamps are nondecreasing.