#2962
Count Subarrays Where Max Element Appears at Least K Times
specialist · 675 · lc medium +30 · verified · 62.4% accepted · 1,709 likes · top 64%
Description
Given an integer array nums and positive integer k, count subarrays that contain the global maximum of nums at least k times.
Return that count.
Example 1:
Input: nums = [1,3,2,3,3], k = 2
Output: 6
Explanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].
Example 2:
Input: nums = [1,4,2,1], k = 3
Output: 0
Explanation: No subarray contains the element 4 at least 3 times.
Code
1
2
3