Curefit's search input should avoid sending a search request for every keystroke. Given a timestamped sequence of queries, return the query values that would trigger requests using trailing-edge debounce.
A query triggers a request only when no newer query arrives within delay milliseconds. If a newer query arrives before or exactly when the pending request is due, treat it as replacing the pending query. For this problem, an event arriving exactly at the due time is processed before the pending request is emitted.
Implement debounced_search(events, delay), where events is a list of [timestamp, query] pairs ordered by nondecreasing timestamp. timestamp and delay are nonnegative integers measured in milliseconds, and query is a string. Return a list of query strings in the order their debounced requests are sent. Do not return request timestamps.
def debounced_search(events, delay):