3129. Find All Possible Stable Binary Arrays I Medium

@problem@discussion
#Dynamic Programming#Prefix Sum



1/**
2 * [3129] Find All Possible Stable Binary Arrays I
3 *
4 * You are given 3 positive integers zero, one, and limit.
5 * A <span data-keyword="binary-array">binary array</span> arr is called stable if:
6 * 
7 * 	The number of occurrences of 0 in arr is exactly zero.
8 * 	The number of occurrences of 1 in arr is exactly one.
9 * 	Each <span data-keyword="subarray-nonempty">subarray</span> of arr with a size greater than limit must contain both 0 and 1.
10 * 
11 * Return the total number of stable binary arrays.
12 * Since the answer may be very large, return it modulo 10^9 + 7.
13 *  
14 * <strong class="example">Example 1:
15 * <div class="example-block">
16 * Input: <span class="example-io">zero = 1, one = 1, limit = 2</span>
17 * Output: <span class="example-io">2</span>
18 * Explanation:
19 * The 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.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">zero = 1, one = 2, limit = 1</span>
24 * Output: <span class="example-io">1</span>
25 * Explanation:
26 * The only possible stable binary array is [1,0,1].
27 * Note that the binary arrays [1,1,0] and [0,1,1] have subarrays of length 2 with identical elements, hence, they are not stable.
28 * </div>
29 * <strong class="example">Example 3:
30 * <div class="example-block">
31 * Input: <span class="example-io">zero = 3, one = 3, limit = 2</span>
32 * Output: <span class="example-io">14</span>
33 * Explanation:
34 * All the possible stable binary arrays are [0,0,1,0,1,1], [0,0,1,1,0,1], [0,1,0,0,1,1], [0,1,0,1,0,1], [0,1,0,1,1,0], [0,1,1,0,0,1], [0,1,1,0,1,0], [1,0,0,1,0,1], [1,0,0,1,1,0], [1,0,1,0,0,1], [1,0,1,0,1,0], [1,0,1,1,0,0], [1,1,0,0,1,0], and [1,1,0,1,0,0].
35 * </div>
36 *  
37 * Constraints:
38 * 
39 * 	1 <= zero, one, limit <= 200
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/find-all-possible-stable-binary-arrays-i/
45// discuss: https://leetcode.com/problems/find-all-possible-stable-binary-arrays-i/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn number_of_stable_arrays(zero: i32, one: i32, limit: i32) -> i32 {
51        0
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_3129() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.