Class Solution
-
- All Implemented Interfaces:
public final class Solution2962 - Count Subarrays Where Max Element Appears at Least K Times\.
Medium
You are given an integer array
numsand a positive integerk.Return the number of subarrays where the maximum element of
numsappears at leastktimes in that subarray.A subarray is a contiguous sequence of elements within an array.
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.
Constraints:
<code>1 <= nums.length <= 10<sup>5</sup></code>
<code>1 <= numsi<= 10<sup>6</sup></code>
<code>1 <= k <= 10<sup>5</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final LongcountSubarrays(IntArray nums, Integer k)-
-
Method Detail
-
countSubarrays
final Long countSubarrays(IntArray nums, Integer k)
-
-
-
-