Tap here to switch tabs
Problem
Submissions

Problem: Count Substrings That Satisfy K-Constraint I

med
30 min
Try to solve the Count Substrings That Satisfy K-Constraint I problem.

Statement

You are given a binary string s and an integer k.

A binary string satisfies the kk constraint if at least one of the following conditions holds:

  • The total count of '0' characters is at most k.

  • The total count of '1' characters is at most k.

Return the total number of substrings of s that satisfy the kk constraint.

Constraints:

  • 1≤1 \leq s.length ≤50\leq 50

  • 1≤1 \leq k ≤\leq s.length

  • s[i] is either '0' or '1'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Substrings That Satisfy K-Constraint I

med
30 min
Try to solve the Count Substrings That Satisfy K-Constraint I problem.

Statement

You are given a binary string s and an integer k.

A binary string satisfies the kk constraint if at least one of the following conditions holds:

  • The total count of '0' characters is at most k.

  • The total count of '1' characters is at most k.

Return the total number of substrings of s that satisfy the kk constraint.

Constraints:

  • 1≤1 \leq s.length ≤50\leq 50

  • 1≤1 \leq k ≤\leq s.length

  • s[i] is either '0' or '1'.