Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Debounce From Scratch
00:00
5 left

Debounce From Scratch

MediumPython

Problem

In Informatica Intelligent Data Management Cloud, an asset search field should avoid processing every keystroke. Implement a deterministic simulation of a trailing-edge debounce operation that emits only the most recent event after no newer event arrives during the configured delay.

Formal Specification

Implement debounce(events, delay), where events is a list of [timestamp, value] pairs sorted by nondecreasing integer timestamp, and delay is a positive integer quiet period. Each value may be a string or another JSON-compatible value. Return a list of [invocation_timestamp, value] pairs.

When an event arrives, replace the pending event and reset its deadline to timestamp + delay. If the next event arrives at or after the pending deadline, emit the pending event at its deadline before processing the new event. Emit any remaining pending event after the input ends. This models trailing-edge debounce behavior.

Constraints

  • 0 <= events.length <= 10^5
  • Timestamps are integers in nondecreasing order
  • 1 <= delay <= 10^9
  • Event values are JSON-compatible
  • Events at exactly the deadline emit the previous value before the new event is processed

Function Signature

def debounce(events, delay):
Interviewer

Your question is Debounce From Scratch. 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.