FastPrepPer-Client Sliding-Window Rate Limiter
Problems/Per-Client Sliding-Window Rate Limiter

Per-Client Sliding-Window Rate Limiter

General Motors logoGeneral Motors● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report does not give explicit request timestamps, the exact edge where a request expires, or whether rejected requests use up capacity. The reported constructor rejects invalid settings. Our version works across languages, in batches, and only uses valid positive settings. Our version is about 94% the same as the reported question.

Process an ordered batch of requests through a per-client sliding-window rate limiter. Request i belongs to clientIds[i] and arrives at timestamps[i].

For this exercise, assume the batch is processed by one limiter in nondecreasing timestamp order. Before deciding a request at time timestamp, expire that client's accepted requests whose times are at most timestamp - windowSeconds. Accept the request when fewer than maxRequests accepted requests remain for that client. Record only accepted requests; a rejected request does not consume future capacity.

Clients are independent. Requests with the same timestamp are processed in input order. Return one boolean decision for every request, in the original order.

Function

allowRequests(clientIds: String[], timestamps: int[], maxRequests: int, windowSeconds: int) → boolean[]

Examples

Example 1

clientIds = ["A","A","A","A","B"]timestamps = [0,1,2,3,3]maxRequests = 3windowSeconds = 10return = [true,true,true,false,true]

Client A fills its window with accepted requests at times 0, 1, and 2, so its request at time 3 is rejected. Client B has independent capacity and its request is accepted.

Example 2

clientIds = ["x","x","x","x","x"]timestamps = [0,0,1,3,3]maxRequests = 2windowSeconds = 3return = [true,true,false,true,true]

The first two requests fill the window and the request at time 1 is rejected without consuming capacity. At time 3, both accepted requests from time 0 are exactly at the expiration boundary and leave the window before the two new requests are processed.

Constraints

  • 1 <= clientIds.length <= 100000.
  • clientIds.length == timestamps.length.
  • Each client ID is a nonempty printable ASCII string of length at most 50.
  • 0 <= timestamps[i] <= 10^9.
  • timestamps is nondecreasing.
  • 1 <= maxRequests <= 100000.
  • 1 <= windowSeconds <= 10^9.

More General Motors interview questions

  • Come Looking for the Smallest Num Which Must Be > Than a Specific Num. 🔎OA · Seen Mar 2024
  • Prepare Notification 📬OA · Seen Mar 2024
  • Generate Complete Inputs for a Supplied ClassifierONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Metric Counter with a Fake ClockSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
  • Per-Client Sliding-Window Rate LimiterNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Completions API Rate LimiterCursor · PHONE SCREENCursor interview questions
  • Key-Value Store GET and PUT QPSDatabricks · PHONE SCREENDatabricks interview questions
  • Per-Domain Request LimiterExpedia · OAExpedia interview questions
  • Truck Position SubscriberOptiver · OAOptiver interview questions
  • Per-User Sliding-Window Rate LimiterPayPal · OAPayPal interview questions
  • Incident MonitorStripe · OAStripe interview questions
  • Per-Client API Rate LimiterDocker · PHONE SCREEN
  • Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN

General Motors interview experiences

  • General Motors Senior SWE Panel Interview: 1 Experience
See General Motors hiring insights
Saved
class Solution {
    public boolean[] allowRequests(String[] clientIds, int[] timestamps, int maxRequests, int windowSeconds) {
        // Write your code here.
    }
}
Checking account…