FastPrepDrone API Sliding-Window Rate Limiter

Drone API Sliding-Window Rate Limiter

Skydio logoSkydio● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Requests arrive in nondecreasing timestamp order. Request i comes from droneIds[i] at integer time timestamps[i].

Each drone may have at most maxRequests accepted requests in the inclusive interval [timestamps[i] - windowSeconds + 1, timestamps[i]]. A rejected request does not consume quota. Return one boolean per request indicating whether it is accepted.

Function

allowDroneRequests(droneIds: String[], timestamps: int[], windowSeconds: int, maxRequests: int) → boolean[]

Examples

Example 1

droneIds = ["d1","d1","d1","d1"]timestamps = [1,2,3,4]windowSeconds = 3maxRequests = 2return = [true,true,false,true]

The request at time 3 exceeds d1's quota; at time 4, the accepted request at time 1 has left the window.

Example 2

droneIds = ["d1","d2","d1"]timestamps = [5,5,5]windowSeconds = 10maxRequests = 1return = [true,true,false]

Each drone has independent quota state.

Constraints

  • The arrays have the same length from 0 through 100000.
  • Timestamps are nonnegative and nondecreasing.
  • 1 <= windowSeconds, maxRequests <= 100000.
  • Drone IDs are non-empty ASCII strings.

More Skydio problems

See Skydio hiring insights
public boolean[] allowDroneRequests(String[] droneIds, int[] timestamps, int windowSeconds, int maxRequests) {
    // write your code here
}
droneIds["d1","d1","d1","d1"]
timestamps[1,2,3,4]
windowSeconds3
maxRequests2
expected[true,true,false,true]
Checking account…