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
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
Get started
Custom Hook for Debounce/Throttle
00:00
5 left

Custom Hook for Debounce/Throttle

MediumPython

Problem

Tech(x Search receives rapidly changing query events from the UI. Implement a debounce algorithm that emits only the most recent event after no newer event arrives for delay time units.

An incoming event at time t cancels the currently pending event if t is less than or equal to its scheduled emission time. When the next event arrives after the scheduled time, emit the pending event before processing the new one. After processing all input, emit any remaining pending event.

Formal Specification

Implement process_debounced(events, delay), where events is a list of [timestamp, value] pairs sorted by nondecreasing timestamp, and delay is a nonnegative integer. Return a list of [emission_timestamp, value] pairs in emission order. Values are opaque payloads and must be preserved unchanged.

Constraints

  • 0 <= len(events) <= 10^5
  • 0 <= events[i][0] <= 10^9
  • 0 <= delay <= 10^9
  • Events are sorted by timestamp
  • Each event contains exactly one timestamp and one value

Function Signature

def process_debounced(events, delay):
Interviewer

Your question is Custom Hook for Debounce/Throttle. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.