Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

In the binary string "1101001100", find the length of the longest substring that has equally many 0s and 1s and whose length is a multiple of 4.

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

Correct answer: B. 8

Balanced substrings are pairs of equal prefix balances; the extra condition that the length is a multiple of 4 is checked by requiring the two prefix indices to agree mod 4. Ignoring that condition gives a longer, invalid answer.

More Coding Interview Problems questions

Exams that ask this topic