Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Duplicate Events in Time Window
00:00
5 left

Duplicate Events in Time Window

MediumPython

Problem

Given a list of packet events events, where each event is a pair [timestamp, event_id] sorted by non-decreasing timestamp, and an integer window_size, return True if any event_id appears at least twice such that the difference between the two timestamps is at most window_size. Otherwise, return False.

Constraints

  • 1 <= len(events) <= 10^5
  • 0 <= timestamp <= 10^9
  • events[i] = [timestamp, event_id]
  • events is sorted by non-decreasing timestamp
  • 0 <= window_size <= 10^9

Function Signature

def has_duplicate_event_within_window(events, window_size):
Interviewer

Your question is Duplicate Events in Time Window. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.