Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A string of length 6 is formed using letters only from {a, b}, containing no substring "aa" or "bb". How many such strings are there?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
Such strings must alternate, so the first letter determines the whole string, leaving 2 strings. Counting strings avoiding only one of the two patterns gives a larger count.
More Coding Interview Problems questions
- Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3…
- Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?
- Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?
- Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are…
- Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this…
- Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have…