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.
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).
def debounced_search_calls(events, debounce_ms):