2466. Count Ways To Build Good Strings Medium

@problem@discussion
#Dynamic Programming



1/**
2 * [2466] Count Ways To Build Good Strings
3 *
4 * Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following:
5 * 
6 * 	Append the character '0' zero times.
7 * 	Append the character '1' one times.
8 * 
9 * This can be performed any number of times.
10 * A good string is a string constructed by the above process having a length between low and high (inclusive).
11 * Return the number of different good strings that can be constructed satisfying these properties. Since the answer can be large, return it modulo 10^9 + 7.
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: low = 3, high = 3, zero = 1, one = 1
16 * Output: 8
17 * Explanation: 
18 * One possible valid good string is "011". 
19 * It can be constructed as follows: "" -> "0" -> "01" -> "011". 
20 * All binary strings from "000" to "111" are good strings in this example.
21 * 
22 * <strong class="example">Example 2:
23 * 
24 * Input: low = 2, high = 3, zero = 1, one = 2
25 * Output: 5
26 * Explanation: The good strings are "00", "11", "000", "110", and "011".
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= low <= high <= 10^5
32 * 	1 <= zero, one <= low
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/count-ways-to-build-good-strings/
38// discuss: https://leetcode.com/problems/count-ways-to-build-good-strings/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn count_good_strings(low: i32, high: i32, zero: i32, one: i32) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2466() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.