Data Structures & AlgorithmsHardTCS NQT Digital · Infosys
Problem: How many strings of length 3 over the alphabet {a, b, c} contain no two consecutive a's?
- A. 27
- B. 22
- C. 21
- D. 5
Correct answer: B. 22
Strings containing "aa": aaa, aab, aac, baa, caa = 5, so 27 − 5 = 22. 27 removes nothing, counting aaa twice gives 21, and 5 counts the bad strings.
More Coding Interview Problems questions
- Problem: The number of subsets of {1, 2, 3, 4} whose elements sum to exactly 5 (the empty set is excluded) is what value?
- Problem: The number of ways to make 15 using coins of values 2, 3 and 5, where the order of coins does not matter, is what value?
- Problem: The sum of the numbers obtained by repeatedly removing the first and last elements of [1, 2, 3, 4, 5, 6, 7, 8] and adding them as…
- Problem: What is the remainder when 2^100 is divided by 9?
- Problem: The sum of all three-digit palindromic numbers (100–999) is what value?
- Problem: How many integers n with 0 ≤ n ≤ 255 have exactly four 1-bits in their binary representation?