Data Structures & AlgorithmsHardGATE CS · TCS NQT

What is the length of the longest contiguous substring of the binary string 1100101101 that contains equal numbers of 0s and 1s?

  1. A. 6
  2. B. 10
  3. C. 8
  4. D. 12

Correct answer: C. 8

Map each 0 to -1 and each 1 to +1; a balanced substring is a pair of equal prefix sums, and the longest one is the maximum gap between first and last occurrence.

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

Exams that ask this topic