Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Debounce Rapid Input Events
00:00
5 left

Debounce Rapid Input Events

MediumPython

Problem

Virtu Financial's Triton platform receives rapid user input events, such as symbol searches or filter changes. Implement a deterministic simulation of a trailing-edge debounce operation that keeps only the most recent event in each burst.

Given timestamped events and a debounce delay, emit an event only when no later event arrives before its scheduled execution time. Each emitted result must contain the scheduled execution timestamp and the latest event value.

An event scheduled for time t + delay is emitted before processing a new event at time t + delay. Input events are sorted by nondecreasing timestamp. Do not use real timers, sleeping, browser APIs, or asynchronous code.

Formal Specification

Implement debounce_events(events, delay).

  • events is a list of two-item lists [timestamp, value], where timestamp is an integer and value is a string.
  • delay is a nonnegative integer.
  • Return a list of two-item lists [execution_timestamp, value] in execution order.
  • If multiple events belong to one burst, emit only the final event in that burst.

Constraints

  • 0 <= events.length <= 10^5
  • 0 <= events[i][0] <= 10^9
  • 0 <= delay <= 10^9
  • Event timestamps are sorted in nondecreasing order
  • Each event value is a nonempty string

Function Signature

def debounce_events(events, delay):
Interviewer

Your question is Debounce Rapid Input 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.