Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many binary strings of length 8 have every maximal run of equal digits of length at least 2?

  1. A. 30
  2. B. 26
  3. C. 16
  4. D. 128

Correct answer: B. 26

Build the string from runs of lengths ≥ 2 that alternate between 0 and 1: compositions of n into parts of size at least 2, times 2 for the first digit. The count is 2 · f(n) with f(n) = f(n−2) + f(n−3) + ... a linear recurrence over the last run's length.

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

Exams that ask this topic