Data Structures & AlgorithmsHardTCS NQT · CAT
Problem: How many 4-letter strings over {A, B, C} have no letter appearing more than twice?
- A. 78
- B. 54
- C. 81
- D. 36
Correct answer: B. 54
Remove strings with a letter at least 3 times: 3 · (4 · 2 + 1) = 27, so 81 − 27 = 54. Removing only AAAA-type strings gives 78, 81 removes nothing, and 36 counts strings using all three letters.
More Coding Interview Problems questions
- Problem: The binary tree with root 10, left child 5, right child 15, and 5 having right child 7, 15 having left child 12, is traversed in…
- Problem: A list starts as [8, 3, 5]. Three insertion steps add the numbers 4, 9, 1 at the front of the list (each is inserted at index 0)…
- Problem: A deque starts as [2, 4, 6]. The operations are: push front 1, push back 8, pop front, push back 3. What is the sum of the final…
- Problem: The string "tenet" is considered. How many of its substrings (by index range, length at least 2) are palindromes?
- Problem: Water fills a 1-dimensional container with walls of heights [4, 1, 3, 1, 2]. Each cell holds water up to the minimum of the…
- Problem: Compute the sum of all integers from 1 to 999 whose digits are all odd.