FastPrepChronological Sliding-Window Request Counter
Problems/Chronological Sliding-Window Request Counter

Chronological Sliding-Window Request Counter

Careem logoCareem● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Careem onsite interview. The task counts requests in the last n minutes, for any n, over requests that arrive in time order. The interview also talked about many threads and about making the design easy to extend. Our version works on a finite list of inputs and keeps the counting task. It is about 90% the same as the reported question. Handling many threads at once is left to the editorial as a design topic, and is not part of the input.

Process chronological operations describing request arrivals and count queries.

  • ["ADD", t] records one request at integer timestamp t.
  • ["COUNT", t, n] asks how many prior ADD timestamps 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
All Careem interview questionsSee Careem hiring insights
Saved
class Solution {
    public int[] processRequestOperations(String[][] operations) {
        // Write your code here.
    }
}
Checking account…