Skip to content

Commit de7c45d

Browse files
committed
31-03-2024
1 parent 9dd2734 commit de7c45d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

2024/03 - March/31-03-2024.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
3+
Author : Manas Rawat
4+
Date : 31/03/2024
5+
Problem : Count Subarrays With Fixed Bounds
6+
Difficulty : Hard
7+
Problem Link : https://leetcode.com/problems/count-subarrays-with-fixed-bounds/description/
8+
Video Solution : NA
9+
10+
*/
11+
12+
13+
class Solution {
14+
public:
15+
long long countSubarrays(vector<int>& nums, int minK, int maxK) {
16+
long long ans=0;
17+
int maxi=-1, mini=-1;
18+
int s=nums.size();
19+
for(int r=0, l=0; r<s; r++){
20+
int x=nums[r];
21+
if (x<minK ||x>maxK){
22+
l=r+1;
23+
continue;
24+
}
25+
if (x==maxK) maxi=r;
26+
if (x==minK) mini=r;
27+
ans+=max((min(maxi, mini)-l+1),0);
28+
}
29+
return ans;
30+
}
31+
};

0 commit comments

Comments
 (0)