Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

operations =
arguments =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

A trie stores characters in a tree; each path from root corresponds to a prefix.

Approach

Each node holds a map of children and a boolean end.

  • insert: create nodes along the word path and mark the last node as end.
  • search: follow the path and require end at the end.
  • startsWith: follow the path only.

Why it works

Common prefixes share nodes, making prefix queries efficient.

Code
Loading...
Complexity
Time: O(L) per operation
Space: O(total characters inserted)
Solution
Updated: 2026-02-23

Idea

A trie stores characters in a tree; each path from root corresponds to a prefix.

Approach

Each node holds a map of children and a boolean end.

  • insert: create nodes along the word path and mark the last node as end.
  • search: follow the path and require end at the end.
  • startsWith: follow the path only.

Why it works

Common prefixes share nodes, making prefix queries efficient.

Code
Loading...
Complexity
Time: O(L) per operation
Space: O(total characters inserted)