PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Design autocomplete with Trie

Last updated: May 24, 2026

Quick Overview

This question evaluates understanding of Trie-based string indexing, augmented per-node metadata for efficient prefix queries, and algorithmic analysis of insert, update, delete, and topK operations including their time and space complexity.

  • Medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Design autocomplete with Trie

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Design and implement an autocomplete service using a prefix tree (Trie). Support operations insert(word, weight), update(word, newWeight), delete(word), and topK(prefix, k) that returns the k highest-weight words sharing the prefix, breaking ties lexicographically. Assume lowercase English letters. Explain the data structures you maintain at each node to make topK efficient, analyze time and space complexity for each operation, and discuss trade-offs (e.g., storing heaps/lists at nodes vs. computing on demand). Dry-run your solution on: insert('cat', 5), insert('car', 3), insert('cart', 8), insert('dog', 2), topK('ca', 2), update('car', 9), topK('ca', 2), delete('cart'), topK('ca', 2).

Quick Answer: This question evaluates understanding of Trie-based string indexing, augmented per-node metadata for efficient prefix queries, and algorithmic analysis of insert, update, delete, and topK operations including their time and space complexity.

Related Interview Questions

  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
  • Consolidate On-Call Rotation Segments - Google (medium)
  • Solve Flower Placement and Directory Deletion - Google (medium)
Google logo
Google
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
7
0

Design and implement an autocomplete service using a prefix tree (Trie). Support operations insert(word, weight), update(word, newWeight), delete(word), and topK(prefix, k) that returns the k highest-weight words sharing the prefix, breaking ties lexicographically. Assume lowercase English letters. Explain the data structures you maintain at each node to make topK efficient, analyze time and space complexity for each operation, and discuss trade-offs (e.g., storing heaps/lists at nodes vs. computing on demand). Dry-run your solution on: insert('cat', 5), insert('car', 3), insert('cart', 8), insert('dog', 2), topK('ca', 2), update('car', 9), topK('ca', 2), delete('cart'), topK('ca', 2).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,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.