Untitled
unknown
plain_text
10 months ago
617 B
3
Indexable
class Solution {
public long countSubarrays(int[] nums, int k) {
int maxE = Arrays.stream(nums).max().getAsInt();
int n = nums.length;
int i = 0, j = 0;
long result = 0;
int countMax = 0;
while (j < n) {
if (nums[j] == maxE) {
countMax++;
}
while (countMax >= k) {
result += n - j;
if (nums[i] == maxE) {
countMax--;
}
i++;
}
j++;
}
return result;
}
}Editor is loading...
Leave a Comment