Practice Length of Longest Subarray With at Most K Frequency
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Length of Longest Subarray With at Most K Frequency
Problem Statement
You are given an integer array nums and an integer k. The frequency of an element x is the number of times it occurs in an array. An array is called good if the frequency of each element in this array is less than or equal to k. Return the length of the longest good subarray of nums. A subarray is a contiguous non-empty sequence of elements within an array.
Source: Length of Longest Subarray With at Most K Frequency on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3,1,2,3,1,2], k = 2
6
# Example 2
nums = [1,2,1,2,1,2,1,2], k = 1
2
# Example 3
nums = [5,5,5,5,5,5,5], k = 4
4
Constraints
Related LeetCode Problems
Practice more problems similar to Length of Longest Subarray With at Most K Frequency.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.