Your question is Deduplicate Alerts in Time Window. 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.
Given a list of metric events sorted by non-decreasing timestamp and an integer window_size, return the alerts that should be emitted after deduplicating duplicates within the last window_size seconds. Each event is a dictionary with timestamp, metric, severity, and value. Two events are duplicates if they have the same metric and severity, and their timestamps differ by at most window_size. Keep the first event and suppress later duplicates inside the active window.
def deduplicate_alerts(events, window_size):