Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Autocomplete Request Debouncer Cache

HardPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Constraints

  • 1 <= len(events) <= 10^5
  • 0 <= timestamp <= 10^9
  • Timestamps are non-decreasing
  • 0 <= len(query) <= 100
  • 1 <= debounce_ms, cache_ttl_ms <= 10^9

Function Signature

def optimize_autocomplete(events, debounce_ms, min_length, cache_ttl_ms):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output