Find All Possible Stable Binary Arrays II

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 0 in arr is exactly num_zeros.
  • The number of occurrences of 1 in arr is exactly num_ones.
  • Each subarray of arr with a size greater than limit must contain at least one occurrence of both 0 and 1.

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
Inputzero = 1, one = 1, limit = 2
Output2
The two possible stable binary arrays are [1,0] and [0,1].
Example 2
Inputzero = 1, one = 2, limit = 1
Output1
The only possible stable binary array is [1,0,1].

Constraints

  • 1 <= zero, one, limit <= 1000

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate