Class Solution
-
- All Implemented Interfaces:
public final class Solution3261 - Count Substrings That Satisfy K-Constraint II.
Hard
You are given a binary string
sand an integerk.You are also given a 2D integer array
queries, where <code>queriesi = l<sub>i</sub>, r<sub>i</sub></code>.A binary string satisfies the k-constraint if either of the following conditions holds:
The number of
0's in the string is at mostk.The number of
1's in the string is at mostk.
Return an integer array
answer, whereanswer[i]is the number of substrings of <code>sl<sub>i</sub>..r<sub>i</sub></code> that satisfy the k-constraint.Example 1:
Input: s = "0001111", k = 2, queries = \[\[0,6]]
Output: 26
Explanation:
For the query
[0, 6], all substrings ofs[0..6] = "0001111"satisfy the k-constraint except for the substringss[0..5] = "000111"ands[0..6] = "0001111".Example 2:
Input: s = "010101", k = 1, queries = \[\[0,5],1,4,2,3]
Output: 15,9,3
Explanation:
The substrings of
swith a length greater than 3 do not satisfy the k-constraint.Constraints:
<code>1 <= s.length <= 10<sup>5</sup></code>
s[i]is either'0'or'1'.1 <= k <= s.length<code>1 <= queries.length <= 10<sup>5</sup></code>
<code>queriesi == l<sub>i</sub>, r<sub>i</sub></code>
<code>0 <= l<sub>i</sub><= r<sub>i</sub>< s.length</code>
All queries are distinct.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-