Data Structures & AlgorithmsModerateTCS NQT · CAT · MBA placement

How many words of length 6 over a three-letter alphabet {x, y, z} have no two adjacent letters equal?

  1. A. 99
  2. B. 96
  3. C. 486
  4. D. 48

Correct answer: B. 96

The first letter has 3 choices and each later letter has 2 (anything except the previous letter), so the count is 3 · 2⁵ = 96. Forgetting that each step still avoids one letter gives 3⁶ minus a wrong correction.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic