Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE
Problem: A trie stores the words "apple", "app", "apply", "ape", "banana". How many stored words start with the prefix "app" (including a word equal to the prefix)?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
A trie answers prefix queries by walking the prefix and counting the words below that node. Counting stored words that merely share the first letter 'a' overcounts with 'ape'.
More Coding Interview Problems questions
- Problem: Subtraction game: from n stones a player may remove 1, 3 or 4 stones; the player who cannot move loses (no stones left on their…
- Problem: On the 4-cycle C4 (vertices 0-1-2-3-0), a walker starts at 0 and takes exactly 3 steps, each to an adjacent vertex. How many…
- Problem: The array [7, 3, 9, 1, 5] is processed by a selection that finds the position of the maximum, removes it, and repeats. The…
- Problem: How many 4-digit numbers (1000–9999) are palindromes (read the same forwards and backwards in decimal)?
- Problem: The string "abcabcabc" has how many distinct substrings of length 3?
- Problem: What is the number of walks of length 4 that start and end at the same vertex in the complete graph K3 (vertices 0, 1, 2, each…