Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
Backend Engineering Senior programming

LeetCode #208 - Implement Trie (Prefix Tree)

Given a list of words, implement a trie with insert, search, and startsWith methods. Your implementation should support insert and search queries efficiently.

Method Signatures:


def insert(self, word: str) -> None: 
    pass 
def search(self, word: str) -> bool: 
    pass 
def startsWith(self, prefix: str) -> bool: 
    pass

Input/Output:


Input: ['apple', 'app'], search('app') -> true
Input: ['apple', 'app'], startsWith('ap') -> true

Constraints:


  • All input words are lowercase alphabets.

  • Insert, search, and startsWith operations should be efficient (preferably O(M) where M is the length of the word).

Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free

More Backend Engineering Interview Prep

Design a system that can handle leading traffic for a social media platform's notifications system. Describe the key components you would include to ensure both scalability and reliability.
Backend Engineering · Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Link copied to clipboard