⚡️ Tryprepforge
Backend Engineering Senior programming

LeetCode #208 - Implement Trie (Prefix Tree) \nGiven a list of words, implement a trie with insert, search, and startsWith methods. Your implementation should support insert and search queries efficiently. \n### Method Signatures: \n```python \ndef insert(self, word: str) -> None: \n pass \ndef search(self, word: str) -> bool: \n pass \ndef startsWith(self, prefix: str) -> bool: \n pass \n``` \n### Input/Output: \nInput: ['apple', 'app'], search('app') -> true \nInput: ['apple', 'app'], startsWith('ap') -> true \n### Constraints: \n- All input words are lowercase alphabets. \n- Insert, search, and startsWith operations should be efficient (preferably O(M) where M is the length of the word). \n

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code formatting, and immersive audio explanations.

No credit card required

More Backend Engineering Interview Prep

Link copied to clipboard