Data Structures & AlgorithmsHardGATE CS · CAT · MBA placement

How many binary strings of length 6 have exactly 4 maximal runs (blocks of equal consecutive digits)?

  1. A. 24
  2. B. 20
  3. C. 10
  4. D. 21

Correct answer: B. 20

A string with k runs is determined by its first digit and by which of the n − 1 gaps are 'changes', so the count is 2 × C(n − 1, k − 1). Counting only the change placements (without the factor 2) gives half the answer.

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

Exams that ask this topic