Your question is Parse Logs for Error Alerts. 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 log lines logs, a list of error substrings patterns, and an integer window_size, write a function that scans the logs in order and returns alert payloads for matching errors. A line should produce an alert if it contains any pattern and includes a valid JSON object with keys service, code, and message. Deduplicate alerts so the same (service, code, message) is emitted at most once within the last window_size matching alerts.
def extract_error_alerts(logs, patterns, window_size):