Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Debounce or Throttle Events
00:00
5 left

Debounce or Throttle Events

MediumPython

Problem

A search experience can receive many input events while a user is typing. Implement a trailing-edge debounce simulation that keeps only the latest event during each burst and emits it after a period of inactivity.

Formal Specification

Implement debounce_events(events, wait), where events is a list of [timestamp, value] pairs sorted by nondecreasing timestamp. Each timestamp is an integer number of milliseconds, and wait is the required quiet interval in milliseconds.

For every event, schedule its value to be emitted at timestamp + wait. If another event arrives before that scheduled time, cancel the previous pending emission and schedule the new event instead. If an event arrives exactly at the scheduled time, emit the previous event first, because the quiet interval has completed. Return all emitted events as [emission_timestamp, value] pairs, including the final pending event.

Do not mutate events. You are simulating debounce behavior, not using timers or browser APIs.

Constraints

  • 0 <= events.length <= 10^5
  • 0 <= events[i][0] <= 10^9
  • Timestamps are sorted in nondecreasing order
  • 1 <= wait <= 10^9
  • Each event value is a string, integer, or boolean

Function Signature

def debounce_events(events, wait):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.