Find the Longest Equal Subarray
You are given a 0-indexed integer array nums and an integer k.
A subarray is called equal if all of its elements are equal. Note that the empty subarray is an equal subarray.
Return the length of the longest possible equal subarray after deleting at most k elements from nums.
A subarray is a contiguous, possibly empty sequence of elements within an array.
Example 1
Input
nums = [1,3,2,3,1,3], k = 3Output
3It's optimal to delete the elements at index 2 and index 4, making the longest equal subarray
[3, 3, 3] of length 3.Example 2
Input
nums = [1,1,2,2,1,1], k = 2Output
4It's optimal to delete the elements at index 2 and index 3, leaving
[1, 1, 1, 1], so the answer is 4.Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= nums.length
- 0 <= k <= nums.length