DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Trie

Implement Trie (Prefix Tree)

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Implement Trie (Prefix Tree)** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Array[26] children + isEnd flag at each node **Edge Cases to Consider:** - (1) Insert empty string - (2) Search prefix matching full word - (3) Common prefix words

Examples

Example 1
Input: insert("apple"); search("apple"); search("app"); startsWith("app")
Output: true; false; true
Explanation: Classic
Example 2
Input: insert("a"); search("a")
Output: true
Explanation: Single char
Example 3
Input: insert("ab"); startsWith("a"); startsWith("ab"); startsWith("abc")
Output: true; true; false

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪Insert empty string
  • ▪Search prefix matching full word
  • ▪Common prefix words
Frequently Asked At
GoogleAmazonMicrosoftMetaAdobeFlipkart