PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Snapchat

Implement a search autocomplete suggestion service

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in designing efficient prefix-matching and ranking mechanisms, including management of incremental query state and frequency-based ordering.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Implement a search autocomplete suggestion service

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Design an autocomplete component that suggests the most relevant search phrases as a user types. You are given historical sentences with their usage counts. The system receives the query one character at a time and must return suggestions after each character. ### Requirements - Initialize with: - `sentences[i]`: a previously typed sentence - `times[i]`: how many times it was typed - On each input character `c`: - If `c != '#'`, append it to the current query prefix and return the **top 3** matching historical sentences that start with this prefix. - If `c == '#'`, treat the current query as a completed sentence: - increment its count by 1 (add it if new) - clear the current query - return an empty list ### Ranking - Higher count ranks first. - Ties are broken by lexicographically smaller sentence first. ### API Implement a class with methods: - `AutocompleteSystem(sentences, times)` - `input(c) -> List[str]` ### Constraints (reasonable interview constraints) - Number of historical sentences: up to `2 * 10^4` - Sentence length: up to `100` - Number of `input()` calls: up to `2 * 10^4`

Quick Answer: This question evaluates proficiency in designing efficient prefix-matching and ranking mechanisms, including management of incremental query state and frequency-based ordering.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
6
0
Loading...

Design an autocomplete component that suggests the most relevant search phrases as a user types.

You are given historical sentences with their usage counts. The system receives the query one character at a time and must return suggestions after each character.

Requirements

  • Initialize with:
    • sentences[i] : a previously typed sentence
    • times[i] : how many times it was typed
  • On each input character c :
    • If c != '#' , append it to the current query prefix and return the top 3 matching historical sentences that start with this prefix.
    • If c == '#' , treat the current query as a completed sentence:
      • increment its count by 1 (add it if new)
      • clear the current query
      • return an empty list

Ranking

  • Higher count ranks first.
  • Ties are broken by lexicographically smaller sentence first.

API

Implement a class with methods:

  • AutocompleteSystem(sentences, times)
  • input(c) -> List[str]

Constraints (reasonable interview constraints)

  • Number of historical sentences: up to 2 * 10^4
  • Sentence length: up to 100
  • Number of input() calls: up to 2 * 10^4

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.