2962. Count Subarrays Where Max Element Appears at Least K Times
Содержание
class Solution:
def countSubarrays(self, nums: List[int], k: int) -> int:
mx = max(nums)
n = len(nums)
res = cnt = j = 0
for x in nums:
while j < n and cnt < k:
cnt += nums[j] == mx
j += 1
if cnt < k:
break
res += n - j + 1
cnt -= x == mx
return res