Your question is Autocomplete Request Debouncer Cache. 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 an autocomplete request optimizer for a mobile search box. Given a list of timestamped query updates, return the timestamps and query strings that should trigger an API call. A call should only be sent if the user has stopped typing for debounce_ms, the query length is at least min_length, and the same query has not been sent within the last cache_ttl_ms.
def optimize_autocomplete(events, debounce_ms, min_length, cache_ttl_ms):