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.
A typical input consists of three integers:
zero: the number of 0s to useone: the number of 1s to uselimit: the maximum allowed length of any consecutive run of equal bitsReturn a single integer: the number of valid binary arrays modulo .
0 <= zero, one1 <= limitExample 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
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.