Skip to content

Commit a46c066

Browse files
authored
Create 2845. Count of Interesting Subarrays (#777)
2 parents 361baa7 + aafb4c2 commit a46c066

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

2845. Count of Interesting Subarrays

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
long long countInterestingSubarrays(vector<int>& nums, int modulo, int k) {
4+
int n = nums.size();
5+
unordered_map<int, long long> fre;
6+
fre[0]=1;
7+
long long ans =0;
8+
int cnt =0;
9+
for(int r=0; r<n; r++){
10+
if(nums[r]%modulo==k) cnt++;
11+
ans+=fre[((cnt%modulo - k)+modulo)%modulo];
12+
fre[cnt%modulo]++;
13+
}
14+
return ans;
15+
16+
}
17+
};

0 commit comments

Comments
 (0)