HardPro challengePythonJavaScriptTypeScript

Sliding Window Log Limiter

Node.jsRate LimitingAlgorithms

Keep a log of recent timestamps. On each request, drop entries older than
window. Allow if log size < limit; otherwise reject.

solve(limit, window, times) returns array of allow/deny per request.

Sample tests

Test #1At t=100 the t=0 entry is exactly window-aged-out, freeing a slot
Input: [3,100,[0,50,99,100]]
Output: [true,true,true,true]
Test #2Old entries drop out
Input: [2,100,[0,50,150,200]]
Output: [true,true,true,true]
Test #3Limit 1
Input: [1,10,[0,5,10]]
Output: [true,false,true]
Test #4Single request
Input: [5,1000,[0]]
Output: [true]
Test #5Mixed
Input: [2,50,[0,10,20,60,70]]
Output: [true,true,false,true,true]