Complete the code to initialize the fixed window counter dictionary.
counters = [1]We use an empty dictionary {} to store counters for each client in the fixed window algorithm.
Complete the code to get the current timestamp in seconds.
current_time = int(time.[1]())
ctime() which returns a string, not a timestamp.The time.time() function returns the current time in seconds since the epoch as a float. We convert it to int for whole seconds.
Fix the error in the condition that resets the window when the time window has passed.
if current_time - counters[client_id]['start_time'] [1] window_size:
The window resets when the elapsed time is greater than or equal to the window size.
Fill both blanks to update the counter and reset the start time when the window expires.
counters[client_id]['count'] = [1] counters[client_id]['start_time'] = [2]
When the window expires, reset the count to 1 for the new request and update the start time to the current time.
Fill all three blanks to increment the count, check if the request is allowed, and return the correct boolean.
counters[client_id]['count'] [1] 1 if counters[client_id]['count'] [2] max_requests: return [3] else: return True
Increment the count by 1. If count exceeds max requests, return False to block the request; otherwise, allow it.