Practice Degree of an Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of nums, that has the same degree as nums.
Source: Degree of an Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,2,2,3,1]
Output
2
# Example 2
Input
nums = [1,2,2,3,1,4,2]
Output
6
Constraints
nums.length will be between 1 and 50,000.
nums[i] will be an integer between 0 and 49,999.
Related LeetCode Problems
Practice more problems similar to Degree of an Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.