Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 C

How many strings of length 6 over {a, b} have NO position i with s[i] = s[i+2] (for every valid i)?

  1. A. 6
  2. B. 4
  3. C. 64
  4. D. 5

Correct answer: B. 4

Each new letter must differ from the letter two positions earlier, so once the first two letters are chosen the rest is forced. Each later letter must be the other letter, so it is forced; the first two letters can be chosen in 2 × 2 = 4 ways, and the count stays 4 for every length n ≥ 2.

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

Exams that ask this topic