Algorithms
Medium
2831
2832
Find the Longest Equal Subarray
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 = 3
Output: 3
Explanation: It's optimal to delete the elements at index 2 and index 4.
After deleting them, nums becomes equal to [1, 3, 3, 3].
The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.
It can be proven that no longer equal subarrays can be created.

Example 2:

Input: nums = [1,1,2,2,1,1], k = 2
Output: 4
Explanation: It's optimal to delete the elements at index 2 and index 3.
After deleting them, nums becomes equal to [1, 1, 1, 1].
The array itself is an equal subarray, so the answer is 4.
It can be proven that no longer equal subarrays can be created.


Constraints:

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= nums.length
 * 0 <= k <= nums.length
"""
class Solution:
    def longestEqualSubarray(self, nums: List[int], k: int) -> int:
        
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 = 3
Output: 3
Explanation: It's optimal to delete the elements at index 2 and index 4.
After deleting them, nums becomes equal to [1, 3, 3, 3].
The longest equal subarray starts at i = 1 and ends at j = 3 with length equal to 3.
It can be proven that no longer equal subarrays can be created.

Example 2:

Input: nums = [1,1,2,2,1,1], k = 2
Output: 4
Explanation: It's optimal to delete the elements at index 2 and index 3.
After deleting them, nums becomes equal to [1, 1, 1, 1].
The array itself is an equal subarray, so the answer is 4.
It can be proven that no longer equal subarrays can be created.


Constraints:

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= nums.length
 * 0 <= k <= nums.length


Please complete the code below to solve above prblem:
```python
class Solution:
    def longestEqualSubarray(self, nums: List[int], k: int) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [1,3,2,3,1,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [1,1,2,2,1,1], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 4

test_input = { "nums": [1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,1], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,2], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,3,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,2,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,1,1], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,2,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1,2,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,3,1], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,2,1], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,3,2], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,3,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,2,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,2,3], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,2,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [1,2,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [3,3,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [1,2,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,1,3], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,2,3], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1,2,2], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,2,4,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,4,2,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1,3,4,2], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [2,4,2,2], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [4,2,2,3], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [4,1,3,2], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1,1,2,1], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,4,1,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [1,1,1,2], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [4,2,1,4], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,1,4,1], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,1,4,1], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,4,3,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,2,2,4], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,2,2,4], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,3,3,1], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,4,1,4], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,4,1,4], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,2,3,1], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,1,1,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,3,2,5,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [5,3,3,1,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [4,4,2,2,4], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [5,4,2,3,3], "k": 5 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [4,4,4,3,4], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 4

test_input = { "nums": [1,5,5,5,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,1,4,5,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [5,1,5,2,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [5,3,2,3,4], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,2,1,4,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [3,2,2,5,3], "k": 5 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,2,4,4,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [4,3,3,4,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [1,5,4,3,4], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [4,4,2,5,3], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,3,5,2,3], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [1,1,1,1,3], "k": 5 }
assert my_solution.longestEqualSubarray(**test_input) == 4

test_input = { "nums": [1,3,2,5,1], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 1

test_input = { "nums": [3,3,1,4,5], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,2,5,5,4], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,1,5,3,1,1], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [6,4,1,5,5,3], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,2,2,1,2,4], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 4

test_input = { "nums": [1,1,2,2,6,2], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [1,2,3,6,6,2], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,4,5,1,4,1], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,5,6,4,6,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [5,4,2,4,1,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,1,1,3,1,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,4,6,6,6,4], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [3,6,2,5,4,5], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,1,5,6,1,4], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [4,6,6,6,2,4], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,5,5,5,6,4], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [2,3,3,2,3,3], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 4

test_input = { "nums": [5,2,5,3,3,2], "k": 6 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,5,3,2,3,6], "k": 6 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [4,3,2,5,4,2], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,2,4,2,1,3], "k": 3 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,1,3,4,1,6], "k": 6 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,3,7,7,3,2,2], "k": 7 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [5,6,7,7,4,4,2], "k": 5 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [7,2,4,1,3,3,4], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [5,3,1,7,5,5,7], "k": 6 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [4,2,6,2,3,4,6], "k": 6 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,7,6,7,3,7,4], "k": 5 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [3,2,5,1,4,3,4], "k": 4 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [2,3,3,7,2,5,1], "k": 2 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [4,1,6,7,5,3,5], "k": 1 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [3,1,4,1,5,5,6], "k": 6 }
assert my_solution.longestEqualSubarray(**test_input) == 2

test_input = { "nums": [1,5,5,7,7,7,4], "k": 0 }
assert my_solution.longestEqualSubarray(**test_input) == 3

test_input = { "nums": [5,7,4,4,1,6,7], "k": 5 }
assert my_solution.longestEqualSubarray(**test_input) == 2