Chronological Sliding-Window Request Counter
Updated
Problem 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.
Similar questions at other companies
- My Calendar IUber · ONSITE INTERVIEWUber interview questions
- Future-Effective Employee SalaryRippling · ONSITE INTERVIEWRippling interview questions
- Bank Accounts with Balance HistoryMeta · OAMeta interview questions
- Versioned ArrayTrueFoundry · PHONE SCREEN
- Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Employee Ratings Management SystemAmazon · PHONE SCREEN
- Running Medians and PercentilesStackAdapt · PHONE SCREENStackAdapt interview questions
- Run-Length Integer Map: Get and SetAdobe · OAAdobe interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions