3258. Count Substrings That Satisfy K-Constraint I Easy
1/**
2 * [3258] Count Substrings That Satisfy K-Constraint I
3 *
4 * You are given a binary string s and an integer k.
5 * A binary string satisfies the k-constraint if either of the following conditions holds:
6 *
7 * The number of 0's in the string is at most k.
8 * The number of 1's in the string is at most k.
9 *
10 * Return an integer denoting the number of <span data-keyword="substring-nonempty">substrings</span> of s that satisfy the k-constraint.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">s = "10101", k = 1</span>
15 * Output: <span class="example-io">12</span>
16 * Explanation:
17 * Every substring of s except the substrings "1010", "10101", and "0101" satisfies the k-constraint.
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">s = "1010101", k = 2</span>
22 * Output: <span class="example-io">25</span>
23 * Explanation:
24 * Every substring of s except the substrings with a length greater than 5 satisfies the k-constraint.
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">s = "11111", k = 1</span>
29 * Output: <span class="example-io">15</span>
30 * Explanation:
31 * All substrings of s satisfy the k-constraint.
32 * </div>
33 *
34 * Constraints:
35 *
36 * 1 <= s.length <= 50
37 * 1 <= k <= s.length
38 * s[i] is either '0' or '1'.
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-i/
44// discuss: https://leetcode.com/problems/count-substrings-that-satisfy-k-constraint-i/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn count_k_constraint_substrings(s: String, k: i32) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_3258() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.