Skip to content

Commit a72ae0e

Browse files
Add new Sliding Window Problems
1 parent 71a5f50 commit a72ae0e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@
439439
|8|[Permutation In String](https://leetcode.com/problems/permutation-in-string/)|Medium|[Solution](/solutions/sliding-window.md)|
440440
|9|[Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)|Hard|[Solution](/solutions/sliding-window.md)|
441441
|10|[Substring With Concatenation Of All Words](https://leetcode.com/problems/substring-with-concatenation-of-all-words/)|Hard|[Solution](/solutions/sliding-window.md)|
442+
|11|[Count Subarrays With Fixed Count](https://leetcode.com/problems/count-subarrays-with-fixed-bounds/)|Hard|[Solution](/solutions/sliding-window/count-subarrays-with-fixed-count.md)|
442443

443444
## 32. Stack
444445

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Count Subarrays With Fixed Count
2+
3+
```cpp
4+
long long countSubarrays(vector<int>& A, int minK, int maxK) {
5+
long res = 0, jbad = -1, jmin = -1, jmax = -1, n = A.size();
6+
for (int i = 0; i < n; ++i) {
7+
if (A[i] < minK || A[i] > maxK) jbad = i;
8+
if (A[i] == minK) jmin = i;
9+
if (A[i] == maxK) jmax = i;
10+
res += max(0L, min(jmin, jmax) - jbad);
11+
}
12+
return res;
13+
}
14+
```

0 commit comments

Comments
 (0)