Design a rate limiter for an API that allows a maximum of max_requests requests within a time window of time_window seconds for each user. If a user exceeds the allowed requests, the API should deny the requests until the time window resets.
max_requests: an integer representing the maximum number of requests allowed in the time window.time_window: an integer representing the duration of the time window in seconds.user_id: a string representing the unique identifier for the user making the requests.timestamp: an integer representing the current time in seconds since the epoch.True if the request is allowed, False otherwise.Example 1:
rate_limiter(5, 10, 'user1', 1) # Output: True
rate_limiter(5, 10, 'user1', 2) # Output: True
rate_limiter(5, 10, 'user1', 3) # Output: True
rate_limiter(5, 10, 'user1', 11) # Output: True
rate_limiter(5, 10, 'user1', 12) # Output: True
rate_limiter(5, 10, 'user1', 13) # Output: False
1 <= max_requests <= 1001 <= time_window <= 1001 <= timestamp <= 10^9max_requests = 5, time_window = 10, user_id = 'user1', timestamp = 1OutputTrueWhyThe first request is allowed as it's within the limit.max_requests = 5, time_window = 10, user_id = 'user1', timestamp = 13OutputFalseWhyThe user has made 5 requests within the last 10 seconds, so this request is denied.1 <= max_requests <= 1001 <= time_window <= 1001 <= timestamp <= 10^9def rate_limiter(max_requests: int, time_window: int, user_id: str, timestamp: int) -> bool: