Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A string of 6 characters is formed from the letters {a, b} such that no two adjacent characters are equal. How many such strings are there?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Once the first letter is chosen, each following letter is forced to differ from its predecessor. With two choices for the first letter, there are two strings.
More Coding Interview Problems questions
- Problem: The Euclidean distance squared between (1,2) and (4,6) is what integer?
- Problem: In the sequence 2, 3, 5, 8, 12, 17, … each term increases by one more than the previous increase (differences 1, 2, 3, 4, …)…
- Problem: How many 4-element subsets of {1, 2, ..., 8} have a sum that is a multiple of 5?
- Problem: The array [4, 9, 16, 25] has its square roots summed. What is the sum of the square roots of these four numbers?
- Problem: A grid has 5 cells in a row, each painted red or blue. How many colourings have no two adjacent cells of the same colour?
- Problem: What is the largest integer n such that n! has at most 3 trailing zeros in base 10?