Question bank › Trie
Dsa Trie Easy

Word Count in a Sentence

You need to create a word counting system that can count occurrences of words in a provided sentence. Implement a Trie structure to add words and count their occurrences. Implement the methods: 1. `add_word(word: str)` - add a word to the trie. 2. `get_count(word: str) -> int` - returns the count of how many times the word has been added to the trie. Input format: - The first line contains an integer, N (1 ≤ N ≤ 1000), the number of operations. - The following N lines contain operations in the format: - `add <word>` (where <word> is a string of lowercase letters). - `count <word>` (where <word> is a string of lowercase letters). Output format: - For each `count` operation, print the number of occurrences of the word. Example: Input: 5 add hello add world add hello count hello count world Output: 2 1

Key concepts

triecountstrings

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.