Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Debounced Search API Handler

Easy
CodingHash TablesQueueStringsAsked 1 times

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):

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
Instacart Mobile Engineer Interview QuestionsInstacart Interview Questions
Next questions
SpeechifyDebounced Search with Cached ResultsHardAirtableDebounced Local Search FilterEasyMicro1Autocomplete Request Debouncer CacheMedium
Python 3.10