Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Real-Time Sliding Window Scan
00:00
5 left

Real-Time Sliding Window Scan

MediumPython

Problem

Splunk Observability Cloud receives events in nondecreasing timestamp order. Implement a realtime scan that finds the time window containing the largest number of ERROR events within a given duration.

Formal Specification

Implement busiest_error_window(events, window_seconds), where events is a list of two-element lists [timestamp, level]. Timestamps are integer seconds, levels are strings, and events are already sorted by timestamp. A valid window includes error events whose timestamps differ by at most window_seconds, so both endpoints are inclusive.

Return [start_timestamp, end_timestamp, error_count] for the densest window. If multiple windows have the same count, return the one with the earliest start timestamp. The start and end timestamps must be the timestamps of the first and last error events in the selected window. Return [None, None, 0] when the stream contains no error events.

Example 1: events = [[1, "INFO"], [2, "ERROR"], [4, "ERROR"], [7, "ERROR"]], window_seconds = 3 returns [2, 4, 2], because timestamps 2 and 4 are within three seconds, while timestamps 2 and 7 are not.

Example 2: events = [[5, "ERROR"], [6, "WARN"], [6, "ERROR"], [9, "ERROR"]], window_seconds = 1 returns [5, 6, 2], because the first two error events occur within one second.

Constraints

  • 1 <= len(events) <= 10^5
  • 0 <= timestamp <= 10^9
  • level is either "ERROR", "WARN", or "INFO"
  • 0 <= window_seconds <= 10^9
  • Events are sorted by nondecreasing timestamp

Function Signature

def busiest_error_window(events, window_seconds):
Interviewer

Your question is Real-Time Sliding Window Scan. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.