Skip to main content
PreparationZone Logo
PreparationZone
Back to Coding

Coding · Medium · Pro

Implement a Trie with insert and exact search

CodingTrieSenior
Model answerPreview

Approach

  • Each node stores children map and isEnd flag.
  • Insert walks characters, creating nodes as needed.
  • Search returns true only if path exists and isEnd at last char.

Java Solution

Java
public class TrieNode {
    Map<Character, TrieNode> children = new HashMap<>();
    boolean isEnd;
}

pu…