Data Structures & AlgorithmsVery hardGATE CS · CAT · MBA placement

How many binary strings of length 7 contain exactly 3 zeros and NO run of three equal consecutive digits (neither 000 nor 111 appears)?

  1. A. 18
  2. B. 22
  3. C. 3
  4. D. 35

Correct answer: A. 18

Build the string from runs: each run has length 1 or 2 and alternates between 0 and 1. Counting compositions of the zeros into runs of size at most 2 gives the answer. Ignoring the run-length cap gives C(7, 3) = 35 instead.

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

Exams that ask this topic