Find All Possible Stable Binary Arrays I
You are given 3 positive integers num_zeros, num_ones, and limit.
A binary array arr is called stable if:
- The number of occurrences of
0inarris exactlynum_zeros. - The number of occurrences of
1inarris exactlynum_ones. - Each subarray of
arrwith a size greater thanlimitmust contain at least one occurrence of both0and1.
Return an integer denoting the total number of stable binary arrays.
Since the answer may be very large, return it modulo 10^9 + 7.
Example 1
Input
zero = 1, one = 1, limit = 2Output
2The two possible stable binary arrays are [1,0] and [0,1], as both arrays have a single 0 and a single 1, and no subarray has a length greater than 2.
Example 2
Input
zero = 1, one = 2, limit = 1Output
1The only possible stable binary array is [1,0,1]; [1,1,0] and [0,1,1] each have a subarray of length 2 with identical elements, so they are not stable.
Constraints
- 1 <= zero, one, limit <= 200