Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 C

How many strings of length 5 over the alphabet {a, b, c} contain no two adjacent equal letters when the letter is a or b (two adjacent c's are allowed)?

  1. A. 99
  2. B. 108
  3. C. 243
  4. D. 41

Correct answer: A. 99

Count with a DP on the last letter: from a or b you may go to the other letter or to c, and from c you may go to any letter. The rule restricts only adjacent a's and b's, so the transitions are not symmetric.

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

Exams that ask this topic