bits. Cut it into three consecutive non-empty parts so that all three parts contain the same number of '1' characters.
Return the number of ways to do this. Two ways differ if at least one cut is in a different place. The answer can be large, so return it modulo 10⁹ + 7.bits='1010010' → 6
There are three ones, so each part needs exactly one. The first cut can go after position 0 or 1 and the second after position 2, 3 or 4: 2 · 3 = 6 ways.
bits='00000' → 6
There are no ones, so any cut into three non-empty parts works: two of the four gaps, C(4, 2) = 6.
bits='1101' → 2
The valid cuts are "1|1|01" and "1|10|1".
bits.length ≤ 10⁵bits[i] is '0' or '1'bits='1010010'
6
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.