Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Peak Event Window by Duration

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

Your question is Peak Event Window by Duration. 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 an array of integer timestamps timestamps and an integer window_size, return the inclusive start and end timestamps of a window of length window_size that contains the maximum number of events. If multiple windows contain the same maximum number of events, return the one with the earliest start time. The input timestamps may be unsorted and may contain duplicates.

Constraints

  • 1 <= timestamps.length <= 10^5
  • 0 <= timestamps[i] <= 10^9
  • 1 <= window_size <= 10^9
  • Timestamps are integers

Function Signature

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