Count the number of binary arrays that satisfy run-length stability constraints.
You are given counts of zeros and ones, along with a limit on how long any consecutive block of equal values may be. Count how many binary arrays can be formed using exactly the given number of 0s and 1s such that every run of identical bits has length at most the allowed limit.
Return the answer modulo .
This is a counting problem: instead of constructing the arrays, determine how many valid arrangements exist.
Input Format
A typical input consists of three integers:
zero: the number of0s to useone: the number of1s to uselimit: the maximum allowed length of any consecutive run of equal bits
Output Format
Return a single integer: the number of valid binary arrays modulo .
Constraints
0 <= zero, one1 <= limit- The answer may be large, so modulo arithmetic is required.
- The exact platform constraints are not provided here; the intended solution should handle large counts efficiently with dynamic programming.
Example 1
Input
zero = 2, one = 2, limit = 1
Output
2
Explanation
Only alternating arrays are valid: [0,1,0,1] and [1,0,1,0].
Example 2
Input
zero = 3, one = 1, limit = 2
Output
1
Explanation
The only valid arrangement is [0,0,1,0]. Arrays with three consecutive 0s are not allowed.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.