Trie pattern

Prefix Matching

Insert a set of words into a trie, then given a query prefix return all stored words that begin with that prefix, as in an autocomplete search. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 1268
  • Medium
  • 2 approaches

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

TrieLeetCode 1268

Medium

From the first idea to the best one

  1. 01 Brute force · scan every word O(Σ lengths)O(1) space
  2. 02 Optimized · trie subtree O(P + matches)O(letters) space
Each approach plays step by step, with its time and space.

What you will learn

  • How to read Prefix Matching and spot the trie pattern in it
  • Brute force · scan every word: O(Σ lengths) time, O(1) space
  • Optimized · trie subtree: O(P + matches) time, O(letters) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Trie

See Prefix Matching run, step by step

Sign in and this page opens on the animation, with all 1 Trie problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.