← Google Interview Insights

Google·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Google SWE coding round, one question the whole time: implement a Trie with wildcard search. Felt manageable until I started second-guessing my recursion logic mid-interview.

Questions Asked (1)

Q1

Implement a Trie (prefix tree) that supports adding words and searching for words where '.' can match any single character.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The basic Trie structure came to me pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the Trie should support adding words and searching for words where '.' matches any single character. Then, design the Trie with a node structure containing children (e.g., array or hashmap) and a boolean flag for word endings. For search with wildcards, implement a recursive DFS that branches when encountering a '.'.

Pro tip: Mention that using a hashmap for children can save space when the alphabet is large or sparse, but an array offers faster access for fixed small alphabets. Also, discuss the trade-off between recursion depth and iterative approaches for wildcard search.

1. Clarify requirements and constraints

Ask about the character set (e.g., lowercase letters), maximum word length, and whether the wildcard '.' can appear in add operations. Confirm that search should return true if any word matches the pattern.

2. Design Trie node structure

Define a TrieNode class with a children data structure (array of size 26 or hashmap) and a boolean isEndOfWord. Explain your choice based on expected alphabet size and memory considerations.

3. Implement addWord

Iterate through each character of the word, creating new nodes as needed, and mark the final node as end of word. This is straightforward and O(L) time.

4. Implement search with wildcard support

Use recursive DFS: for a normal character, follow the corresponding child; for '.', recursively try all existing children. Return true if any path leads to a node marked as end of word at the end of the pattern.

5. Analyze complexity and discuss optimizations

Time complexity for search is O(26^M) in worst case (M = number of dots), but typically much less. Space is O(total characters). Mention possible optimizations like pruning or caching.

Key Points to Mention

  • Choice of children data structure: array vs hashmap and its impact on time/space
  • Recursive DFS for wildcard matching, including base cases
  • Handling of '.' in search: branching over all possible children
  • Time and space complexity analysis for both add and search
  • Edge cases: empty string, pattern with only dots, no matching words
  • Potential follow-up: supporting '*' wildcard or case-insensitive search

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.