Rate limiter counter
Java
Hard
6 views
Problem Description
Task: given timestamps in seconds, allow at most limit events in last window seconds. Return allowed count.
Output Format
Return value
Constraints
Use two pointers.
Official Solution
static int allowedEvents(int[] t,int window,int limit){int l=0;int ok=0;for(int r=0;r<t.length;r++){while(t[r]-t[l]>=window) l++;int inWindow=r-l+1; if(inWindow<=limit) ok++;}return ok;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!