Ctrl K

Bit Strings Without Long Runs

Hard
You are given three positive integers zeros, ones and max_run. Count the strings made of 0 and 1 that: - contain exactly zeros zeros; - contain exactly ones ones; - never have more than max_run equal characters in a row. The count can be huge, so return it modulo 10⁹ + 7.
Example 1
zeros=2, ones=1, max_run=1 → 1

The two zeros cannot be adjacent, so only 010 works.

Example 2
zeros=2, ones=2, max_run=1 → 2

The bits must alternate: 0101 and 1010.

Example 3
zeros=3, ones=2, max_run=2 → 7

Of the 10 arrangements of three zeros and two ones, three fail: 00011, 10001 and 11000 each have three zeros in a row. That leaves 7.

Constraints
  • 1 ≤ zeros, ones, max_run ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Heaviest Reading Day HardUp and Down Orderings HardMerge Neighbouring Piles in Groups HardArrays With K Record Highs HardCutting a Berry Cake Hard
loading Python…
Input
zeros=2, ones=1, max_run=1
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.