Loading...
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 least k times.
A subarray is a contiguous sequence of elements within an array.
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].
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.
nums.length ≤105nums[i] ≤106k ≤105Click "Run" to test with sample cases or "Submit" to run all tests.