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
Debounce or Throttle Events
00:00
5 left

Debounce or Throttle Events

MediumPython

Problem

The Deliveroo 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

Your question is Debounce or Throttle Events. 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.