Skip to content

Commit d5b7d2b

Browse files
authored
Merge pull request #74 from InflixOP/patch1
Create #2962. Count Subarrays Where Max Element Appears at Least K Ti…
2 parents dfdb21e + 8565b9a commit d5b7d2b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
long long countSubarrays(vector<int>& nums, long long k) {
4+
long long n=nums.size();
5+
long long ans=0;
6+
long long sum=0;
7+
long long l=0,r=0;
8+
while (r<n) {
9+
sum+=nums[r];
10+
while(l<=r&&sum*(r-l+1)>=k){
11+
sum-=nums[l];
12+
l++;
13+
}
14+
ans+=r-l+1;
15+
r++;
16+
}
17+
return ans;
18+
}
19+
};

0 commit comments

Comments
 (0)