Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: Insert the words "car", "cat", "care", "dog", "do", "dot" into an empty trie (one node per character, root has no letter). How many nodes does the trie have, including the root?
- A. 9
- B. 19
- C. 18
- D. 10
Correct answer: D. 10
Shared prefixes share nodes: root + c, a, r, t, e (car/cat/care) + d, o, g, t (do/dog/dot) = 10. Leaving out the root gives 9, giving every character its own node gives 18 (19 with the root).
More Coding Interview Problems questions
- Problem: Count the occurrences of the pattern "aba" in "abababa", where occurrences may overlap.
- Problem: The words "listen", "silent", "enlist", "google", "gogole", "cat", "act", "tac", "dog" are grouped by anagram class (words with…
- Problem: In the binary string "1101001110100110", what is the length of the longest contiguous substring containing equal numbers of 0s…
- Problem: For the string "abcab", count the subsequences of length 3 that are palindromes (choose 3 indices i < j < k with s[i] = s[k]; the…
- Problem: What is the minimum number of characters that must be inserted anywhere in "leetcode" to make it a palindrome?
- Problem: What is the length of the longest valid (well-formed) parentheses substring of ")()())(()" ?