Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Deduplicate Alerts in Time Window

MediumPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Constraints

  • 1 <= len(events) <= 10^5
  • 0 <= window_size <= 10^9
  • events are sorted by non-decreasing timestamp
  • timestamp is an integer
  • metric and severity are non-empty strings

Function Signature

def deduplicate_alerts(events, window_size):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output