HardPro challengePythonJavaScriptTypeScript

Leaky Bucket Rate Limiter

Node.jsRate LimitingAlgorithms

Capacity C, leak rate L units per ms. solve(C, L, requests) where
each request is [time, weight]. Before processing, leak based on elapsed
time. If current + weight ≤ C, accept and add weight; else reject.
Returns array of true/false.

Sample tests

Test #1Partial leak insufficient
Input: [5,0.5,[[0,5],[5,3]]]
Output: [true,false]
Test #2Full leak after 10ms
Input: [5,0.5,[[0,5],[10,5]]]
Output: [true,true]
Test #3No time elapsed
Input: [3,1,[[0,1],[0,1],[0,1],[0,1]]]
Output: [true,true,true,false]
Test #4Fill bucket no leak
Input: [10,0,[[0,5],[0,5],[0,1]]]
Output: [true,true,false]
Test #5Leak refills
Input: [10,1,[[0,10],[10,10]]]
Output: [true,true]