Recall & Review
beginner
What does the problem 'Count Words with Given Prefix' ask you to do?
It asks you to find how many words in a list start with a specific prefix.
Click to reveal answer
intermediate
Why is a Trie (prefix tree) useful for counting words with a given prefix?
A Trie stores words so that common prefixes share nodes, making it fast to count how many words start with a prefix by traversing the prefix path.
Click to reveal answer
beginner
In simple terms, how do you count words with a prefix using a loop?
Check each word one by one and count it if it starts with the prefix.
Click to reveal answer
beginner
What TypeScript string method helps check if a word starts with a prefix?
The method is
startsWith(), which returns true if the string begins with the given prefix.Click to reveal answer
intermediate
What is the time complexity of counting words with a prefix by checking each word individually?
It is O(n * m), where n is the number of words and m is the length of the prefix, because each word is checked against the prefix.
Click to reveal answer
Which TypeScript method checks if a string starts with a specific prefix?
✗ Incorrect
The
startsWith() method returns true if the string begins with the given prefix.What data structure is best for efficiently counting words with a common prefix?
✗ Incorrect
A Trie stores words by their prefixes, allowing fast prefix counting.
If you have 1000 words and a prefix of length 3, what is the rough time complexity to count words with that prefix by checking each word?
✗ Incorrect
You check each of the 1000 words against the prefix of length 3, so O(n * m).
What will the output be after counting words with prefix 'app' in ['apple', 'app', 'banana', 'application']?
✗ Incorrect
'apple', 'app', and 'application' all start with 'app', so count is 3.
Which of these is NOT a good way to count words with a prefix?
✗ Incorrect
A stack does not help with prefix counting.
Explain how you would count the number of words starting with a given prefix using a simple loop.
Think about checking each word one by one.
You got /3 concepts.
Describe why a Trie is efficient for counting words with a given prefix compared to checking each word individually.
Imagine a tree where common beginnings are stored once.
You got /3 concepts.