You are given an integer array nums and an integer k. You can perform the following operation any number of times:
nums by 1.Return the minimum number of operations required to ensure that at least one subarray of size k in nums has all elements equal.
Example 1:
Input: nums = [4,-3,2,1,-4,6], k = 3
Output: 5
Explanation:
nums[1]. The resulting array is [4, 1, 2, 1, -4, 6].nums[2]. The resulting array is [4, 1, 1, 1, -4, 6].[1, 1, 1] of size k = 3 with all elements equal. Hence, the answer is 5.Example 2:
Input: nums = [-2,-2,3,1,4], k = 2
Output: 0
Explanation:
The subarray [-2, -2] of size k = 2 already contains all equal elements, so no operations are needed. Hence, the answer is 0.
Constraints:
2 <= nums.length <= 105-106 <= nums[i] <= 1062 <= k <= nums.lengthLoading editor...
[4,-3,2,1,-4,6] 3