FastPrepHierarchical Fixed-Window Rate Limiter
Problems/Hierarchical Fixed-Window Rate Limiter

Hierarchical Fixed-Window Rate Limiter

Headway logoHeadway● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Headway phone screen. The report gives quotas for each endpoint and for the whole backend. It asks you to discuss shared limiters versus individual ones. Our version uses fixed windows, counts only accepted requests, and follows a fixed rule. You get a fixed, ordered batch of requests. That fills in the boundary and interface details the report left out.

You are given two parallel arrays describing requests in nondecreasing timestamp order:

  • timestamps[i] is the request time in whole seconds.
  • endpoints[i] is the endpoint requested at that time.

Process the requests in order with two fixed-window limits:

  • For each endpoint, accept at most 2 requests during each integer second.
  • Across all endpoints together, accept at most 10 requests during each integer minute. Minute m contains timestamps from 60 * m through 60 * m + 59.

A request is accepted only when both limits have remaining quota. Only an accepted request consumes endpoint and global quota; a rejected request changes neither counter.

Return an array answer where answer[i] is 1 when request i is accepted and 0 when it is rejected.

Function

applyRateLimits(timestamps: int[], endpoints: String[]) → int[]

Examples

Example 1

timestamps = [0,0,0,1]endpoints = ["/search","/search","/search","/search"]return = [1,1,0,1]

The first two requests consume the endpoint's quota for second 0. The third is rejected. Timestamp 1 starts a new endpoint window, so the fourth request is accepted.

Example 2

timestamps = [5,5,5,5,5,5,5,5,5,5,5]endpoints = ["/a","/b","/c","/d","/e","/f","/g","/h","/i","/j","/k"]return = [1,1,1,1,1,1,1,1,1,1,0]

No endpoint exceeds its per-second quota, but the first ten accepted requests fill the shared quota for minute 0. The final request is rejected.

Example 3

timestamps = [58,58,58,58,59,60,60]endpoints = ["/x","/x","/x","/y","/y","/x","/x"]return = [1,1,0,1,1,1,1]

The rejected third request does not consume shared quota. Endpoint /y has its own per-second windows at timestamps 58 and 59. Timestamp 60 starts both a new second and a new minute.

Constraints

  • 1 <= timestamps.length = endpoints.length <= 200000
  • 0 <= timestamps[i] <= 1000000000
  • timestamps is in nondecreasing order.
  • 1 <= endpoints[i].length <= 50
  • Each endpoint contains only lowercase English letters, digits, /, -, and _.

More Headway Phone Screen questions

  • Phone-Number Letter CombinationsPHONE SCREEN · Seen Oct 2026
  • License Checkout and Return ManagerPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
  • Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
  • Realized Gains from a Real-Estate Transaction StreamKikoff · PHONE SCREENKikoff interview questions
  • Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
  • Batched Key Fetch CallbacksAnrok · PHONE SCREEN
  • Earliest Car for Each PassengerWhatNot · PHONE SCREENWhatNot interview questions

Headway interview experiences

  • Headway Karat 1st Interview Round (Same for all level)
All Headway interview questionsSee Headway hiring insights
Saved
class Solution {
    public int[] applyRateLimits(int[] timestamps, String[] endpoints) {
      // write your code here
    }
}
Checking account…