Skip to content

Practice Find the Longest Equal Subarray

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2831
LeetCode Problem

Find the Longest Equal Subarray

Problem Statement

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.

Source: Find the Longest Equal Subarray on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,3,2,3,1,3], k = 3
Output
3

# Example 2

Input
nums = [1,1,2,2,1,1], k = 2
Output
4

Constraints

1 <= nums.length <= 10^5
1 <= nums[i] <= nums.length
0 <= k <= nums.length

Related LeetCode Problems

Practice more problems similar to Find the Longest Equal Subarray.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.