Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many strings of length 4 over the alphabet {0, 1, 2} have no two adjacent characters equal?

  1. A. 25
  2. B. 24
  3. C. 26
  4. D. 28

Correct answer: B. 24

The first character has 3 choices and each of the next 3 characters has 2 choices (any character except the previous one). 3 * 2^3 = 24.

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

Exams that ask this topic