Your question is Sliding Window Rate Violations. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
IBM API Connect must identify client IP addresses whose request rate exceeds a configured threshold. Given request records, return every IP with more than k requests in at least one sliding window of t seconds.
Implement detect_rate_abuse(requests, k, t), where requests is a list of two-element lists [ip, timestamp]. ip is a string and timestamp is an integer number of seconds. The input records may be in any order.
A window is inclusive: requests at timestamps s and s + t belong to the same window. An IP is abusive if some window contains at least k + 1 of its requests. Return the abusive IP addresses once each, sorted lexicographically. Return an empty list if no IP exceeds the threshold.
def detect_rate_abuse(requests, k, t):