#3258

Count Substrings That Satisfy K-Constraint I

easy · 78.9% accepted · 176 likes · top 90%

string · sliding window

Description

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

A binary string satisfies the k-constraint if either of the following conditions holds:

- The number of 0's in the string is at most k.

- The number of 1's in the string is at most k.

Return an integer denoting the number of substrings of s that satisfy the k-constraint.

Solution