#3261

Count Substrings That Satisfy K-Constraint II

international master · 2140 · lc hard +32 · 23.4% accepted · 140 likes · top 3%

Description

You are given binary string s, integer k, and 2D array queries where queries[i] = [li, ri]. A binary string satisfies the k-constraint if its count of 0s or 1s is at most k.

For each query, return the count of substrings within s[li..ri] satisfying the k-constraint.

Code

1
2
3