Harpreet's Newsletter

Harpreet's Newsletter

Implement Trie (Prefix Tree)

Google Interview Question

Harpreet Singh's avatar
Harpreet Singh
Dec 19, 2025
∙ Paid

Problem Overview

Difficulty: Medium
LeetCode Pattern: Trie

Build a Trie (prefix tree) that supports 3 operations:

  1. insert(word)

    1. Store the word in the Trie.

  2. search(word)

    1. Return True if the exact word exists.

    2. Return False otherwise.

  3. startsWith(prefix)

    1. Return True if any word in the Trie starts with the given prefix.

    2. Return False otherwise.

Example
trie = Trie()

trie.…
User's avatar

Continue reading this post for free, courtesy of Harpreet Singh.

Or purchase a paid subscription.
© 2026 Harpreet Singh · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture