Shopee search suggestions should update only after the user has stopped typing for a specified quiet period. Given a chronological stream of input events, implement trailing-edge debouncing and return the events that would trigger a search request.
An event is represented as [timestamp, value], where timestamp is an integer time unit and value is a string. When a new event arrives before the current candidate has remained unchanged for delay time units, replace the candidate with the new event. A candidate triggers at candidate_timestamp + delay when the next event occurs at least delay units later. After processing all events, emit the final candidate at its scheduled trigger time.
Implement debounce_events(events, delay). The input events is a list of timestamp-value pairs sorted by nondecreasing timestamp. Return a list of [trigger_timestamp, value] pairs in chronological processing order. The input list may be empty.
def debounce_events(events, delay):