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

Debounce or Throttle Mechanism

MediumPython

Problem

Shopee search suggestions should update only after the user has stopped typing for a specified quiet period. Given a chronological stream of input events, implement trailing-edge debouncing and return the events that would trigger a search request.

An event is represented as [timestamp, value], where timestamp is an integer time unit and value is a string. When a new event arrives before the current candidate has remained unchanged for delay time units, replace the candidate with the new event. A candidate triggers at candidate_timestamp + delay when the next event occurs at least delay units later. After processing all events, emit the final candidate at its scheduled trigger time.

Formal Specification

Implement debounce_events(events, delay). The input events is a list of timestamp-value pairs sorted by nondecreasing timestamp. Return a list of [trigger_timestamp, value] pairs in chronological processing order. The input list may be empty.

Constraints

  • 0 <= len(events) <= 10^5
  • 0 <= events[i][0] <= 10^9
  • 1 <= delay <= 10^9
  • events is sorted by nondecreasing timestamp
  • Each event value is a nonempty string

Function Signature

def debounce_events(events, delay):
Interviewer

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