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 Utility
00:00
5 left

Debounce or Throttle Utility

MediumPython

Problem

Dream11 search suggestions should update only after the user stops typing for a specified interval. Implement a trailing-edge debounce utility that suppresses intermediate events and emits only the latest event after no newer event arrives within wait time units.

Formal Specification

Write debounce_events(events, wait), where events is a list of events represented as [timestamp, value]. Timestamps are non-decreasing integers, and values may be strings or other JSON-compatible values. Return a new list of [emit_timestamp, value] pairs.

The first event in a burst is replaced whenever another event arrives within wait time units. The latest event is emitted at event_timestamp + wait. If a new event arrives at exactly the pending event's deadline, emit the pending event first, then begin a new burst with the current event. The input list is already complete, so flush the final pending event before returning.

Constraints

  • 0 <= len(events) <= 10^5
  • wait >= 1
  • Timestamps are non-decreasing integers
  • Each event contains exactly one timestamp and one value

Function Signature

def debounce_events(events, wait):
Interviewer

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