core practice · coding problem

Trie prefix membership

Insert ["app","apt","bat"]. Implement startsWith("ap") and search("apt").

The mechanism

A trie stores strings in a tree where each path from the root spells out a prefix. It makes prefix queries (autocomplete, IP routing) take time proportional to the length of the prefix, not the size of the dataset.

Study Trie

Expected evidence

startsWith true; search true; search("ba") true prefix but search("ban") false.

Try this drill in the practice workspace →

Hints when you need them
  • Each node maps char → child.
  • End-of-word flag for complete keys.

Check the sources

Browse all practice briefs