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?

  1. A. 3
  2. B. 1
  3. C. 2
  4. 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

Exams that ask this topic