trie
trie is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.
Interview Signal
Frequently tests problem modeling, edge handling, and verbal clarity.
Common Pitfall
Template-only answers break under follow-up questioning.
Practice Strategy
Practice in 3-5 problem rounds and always review complexity alternatives.
Recommended Progression
Longest Common Prefix
Find the longest common prefix in an array of strings, returning an empty string if none exists.
Word Break
Determine if a string can be fully segmented into dictionary words using array scanning and hash-based lookups for effic…
Word Break II
Given a string and dictionary, return all possible sentences by adding spaces where each word is in the dictionary.
Implement Trie (Prefix Tree)
This problem requires designing a Trie (Prefix Tree) to efficiently store and query strings using hash table concepts fo…
Design Add and Search Words Data Structure
Build a WordDictionary supporting dynamic word addition and search with wildcard matching efficiently using Trie and DFS…
Word Search II
Solve the Word Search II problem using backtracking with pruning to find all words on a board of characters.
Palindrome Pairs
Find all pairs of words in a list that form palindromes when concatenated using efficient scanning and hash mapping.
Lexicographical Numbers
Generate all numbers from 1 to n in lexicographical order using a depth-first search pattern optimized with trie logic f…
Maximum XOR of Two Numbers in an Array
Find the maximum XOR of two numbers in an integer array using efficient bit manipulation techniques.
K-th Smallest in Lexicographical Order
Find the k-th lexicographically smallest integer in a range using a Trie-based approach.
Concatenated Words
Find concatenated words by using dynamic programming and depth-first search to identify valid words made of other words …
Replace Words
Replace words in a sentence using the shortest root from a dictionary, applying efficient array scanning and hash lookup…
Implement Magic Dictionary
Design a Magic Dictionary to allow searching with one-character modifications, using Hash Table and String techniques.
Map Sum Pairs
Design and implement a data structure that supports efficient insertion and sum queries based on string prefixes.
Top K Frequent Words
Solve Top K Frequent Words by counting each word, then ordering ties alphabetically so frequency wins before lexicograph…
Longest Word in Dictionary
Find the longest word in a dictionary that can be built one character at a time from other words in the dictionary.
Prefix and Suffix Search
Design a dictionary to search words by both prefix and suffix using a Trie structure and hash lookups.
Number of Matching Subsequences
Given a string s and a list of words, count how many words are subsequences of s using efficient array scanning and hash…
Short Encoding of Words
Find the minimum length of a reference string encoding an array of words using array scanning and hash lookup efficientl…
Camelcase Matching
Camelcase Matching is a medium difficulty problem where you match queries to a given pattern by inserting lowercase lett…
Stream of Characters
Implement a StreamChecker that detects if any suffix of a character stream matches a given list of words using efficient…
Number of Valid Words for Each Puzzle
Solve the "Number of Valid Words for Each Puzzle" problem with array scanning and hash lookup to efficiently count valid…
Remove Sub-Folders from the Filesystem
Remove sub-folders in a filesystem by filtering out folders nested inside other folders.
Search Suggestions System
Design a search suggestion system that provides the top three lexicographically smallest products matching a search word…
Distinct Echo Substrings
Count the distinct non-empty substrings of a given string that can be formed as the concatenation of a string with itsel…
Maximum XOR With an Element From Array
Solve the Maximum XOR With an Element From Array problem by efficiently finding the maximum XOR for each query using bit…
Count Pairs With XOR in a Range
Count all pairs in an array whose XOR falls within a given range using efficient bit manipulation techniques and a trie …
Maximum Genetic Difference Query
Find the maximum genetic difference along paths in a tree using array scanning and hash lookups with XOR calculations.
Delete Duplicate Folders in System
Solve Delete Duplicate Folders in System by building a trie, serializing child subtrees, and deleting repeated non-empty…
Encrypt and Decrypt Strings
The 'Encrypt and Decrypt Strings' problem involves creating a data structure that can encrypt and decrypt strings using …
K Divisible Elements Subarrays
Count all distinct subarrays with at most k elements divisible by p using array scanning and hash lookup techniques effi…
Sum of Prefix Scores of Strings
The 'Sum of Prefix Scores of Strings' problem involves calculating prefix scores for strings based on their occurrences …
Words Within Two Edits of Dictionary
Identify all words in queries that can match dictionary entries with at most two character changes efficiently using arr…
Extra Characters in a String
The problem asks for the minimum number of extra characters left after optimally breaking a string into substrings found…
Maximum Strong Pair XOR I
Find the maximum XOR of any strong pair in an integer array using array scanning and hash-based lookups efficiently.
Maximum Strong Pair XOR II
Find the maximum XOR among strong pairs in an array using array scanning and hash-based lookups efficiently.
Minimum Cost to Convert String II
Compute the minimum cost to transform source into target using substring replacements with given costs efficiently using…
Count Prefix and Suffix Pairs I
Count all index pairs where one word is both a prefix and suffix of another, using efficient array and string checks.
Find the Length of the Longest Common Prefix
Determine the length of the longest common prefix between two integer arrays using array scanning and hash lookup effici…
Count Prefix and Suffix Pairs II
Count the number of index pairs in a string array where one word is both a prefix and suffix of another using array and …
Shortest Uncommon Substring in an Array
Find the shortest substring for each string in an array that does not appear in any other string efficiently using hashi…
Longest Common Suffix Queries
Find the index of the string in wordsContainer with the longest common suffix for each query efficiently using array and…
Minimum Number of Valid Strings to Form Target I
Use dynamic programming to split target into the fewest prefixes that match any word prefix, while ruling out dead posit…
Longest Common Prefix of K Strings After Removal
Find the longest common prefix length of k strings after removing an element in the array.
Partition String
Partition a string into unique segments using hash table and string manipulation.