Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Debounced Search API Handler

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Debounced Search API Handler. Start with the requirements on the right.

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.

Problem

Implement a function that simulates the core logic behind a debounced search bar. You are given a list of input events, where each event is a pair (timestamp_ms, query) sorted by time, and a debounce_ms delay. Return the list of API calls that should actually be made if a new keystroke cancels any pending request that has not fired yet. Each API call should be represented as (fire_time_ms, query).

Constraints

  • 0 <= len(events) <= 10^5
  • 0 <= timestamp_ms <= 10^9
  • events is sorted by timestamp_ms in non-decreasing order
  • 0 <= len(query) <= 100
  • 1 <= debounce_ms <= 10^6

Function Signature

def debounced_search_calls(events, debounce_ms):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output