Back to problems

Sliding-Window Rate Limiter / Abuse IP Detection

Algorithm · IBM · Medium

Requirements Rate-limiting variant: Signature: rateLimit(userId: Identifier[], time: Integer[], k: Integer, t: Integer) -> Integer[]. userId and time are parallel arrays; event i uses userId[i] and time[i]. Inputs are userId[i], time[i], k, and t. Return an integer array: use 1 when event i passes and 0 when it is rejected. A request may pass only when that user has fewer than k previously accepted requests with timestamps in the inclusive window [time[i] - t, time[i]].…

Checking your access…