You are given an integer array nums and a positive integer k.
Let M be the maximum value in the entire array nums. Return the number of (contiguous) subarrays in which M appears at leastk times.
A subarray is a contiguous sequence of elements within an array.
Examples
Example 1
Input: nums = [1,3,2,3,3], k = 2
Output: 6
Explanation: The maximum value in the array is 3. The subarrays that contain the value 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: The maximum value in the array is 4, and no subarray contains it at least 3 times.
Constraints
1≤nums.length≤105
1≤nums[i]≤106
1≤k≤105
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up