Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Autocomplete Request Debouncer Cache

Medium
Codingnetwork requestsperformanceSearching
Asked 2mo ago|
Micro1
Micro1
Asked 1 times

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):

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
Next questions
InstacartDebounced Search API HandlerEasySpeechifyDebounced Search with Cached ResultsHardBrillioSearch-As-You-Type With DebounceMedium
Python 3.10