Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

In how many ways can the binary string "0110100110" be cut into one or more contiguous segments so that every segment contains equally many 0s and 1s?

  1. A. 19
  2. B. 18
  3. C. 9
  4. D. 16

Correct answer: D. 16

Let d[j] be the number of valid cuttings of the prefix of length j; d[j] = Σ d[i] over starts i where s[i..j−1] is balanced. Counting only the balanced substrings (not partitions of the whole string) answers a different question.

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

Exams that ask this topic