Skip to content

Commit 5c079d2

Browse files
committed
feat: WIP leetcode/leetcoding_challenge/2025/apr2025/week4/count_subarrays_with_fixed_bounds.cpp
1 parent 771442c commit 5c079d2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/onlinePlatform/leetcode/leetcoding_challenge/2025/apr2025/week4/count_subarrays_with_fixed_bounds.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class Solution {
2828
int right = 0;
2929
multiset<int> bst;
3030
while (right < nums.size()) {
31+
cout << "right: " << right << " nextInvalidIndices[right]: " << nextInvalidIndices[right] << endl;
3132
if (nums[right] < minK || nums[right] > maxK) {
33+
cout << "reset" << endl;
3234
bst = multiset<int>();
3335
right++;
3436
left = right;
@@ -37,10 +39,22 @@ class Solution {
3739

3840
bst.insert(nums[right]);
3941

42+
try {
43+
cout << right << " " ;
44+
cout << *begin(bst) << " _ " ;
45+
cout << *prev(end(bst)) << " __ ";
46+
cout << *end(bst) << " ___ " << endl;
47+
} catch (const std::exception& e) {
48+
cout << " _e_ " << endl;
49+
}
50+
4051
while (bst.size() > 0 && *begin(bst) == minK && *prev(end(bst)) == maxK) {
4152
int count = nextInvalidIndices[right] - right;
53+
cout << "add count: " << count << " answer:" << answer << endl;
4254
answer += count;
4355
bst.erase(nums[left]);
56+
57+
cout << "now: " << *begin(bst) << " _ " << *prev(end(bst)) << endl;
4458
left++;
4559
}
4660

@@ -60,8 +74,11 @@ class Solution {
6074
int main() {
6175
Solution soln;
6276

63-
vector<int> nums{1,3,5,2,7,5};
64-
cout << soln.countSubarrays(nums, 1, 5) << endl;
77+
// vector<int> nums{1,3,5,2,7,5};
78+
79+
// cout << soln.countSubarrays(nums, 1, 5) << endl;
80+
vector<int> nums{35054,398719,945315,945315,820417,945315,35054,945315,171832,945315,35054,109750,790964,441974,552913};
81+
cout << soln.countSubarrays(nums, 35054, 945315) << endl;
6582

6683
return 0;
6784
}

0 commit comments

Comments
 (0)