Description
Given a non-empty array of non-negative integers, the degree is the maximum frequency of any element. Find the smallest length subarray that has the same degree as the array.
Examples
Input:
nums = [1,2,2,3,1]Output:
2Explanation:
2 has degree 2, subarray [2,2].
Input:
nums = [4,6,6,6,4,4,5]Output:
3Explanation:
Both 4 and 6 have degree 3. For element 4: shortest subarray covering indices 0 to 5 has length 6. For element 6: shortest subarray covering indices 1 to 3 is [6,6,6] with length 3. The minimum is 3.
Input:
nums = [7,7,8,8,8,9]Output:
3Explanation:
Element 8 has the highest degree of 3. The shortest subarray containing all occurrences of 8 is [8,8,8] with length 3.
Constraints
- •
1 ≤ nums.length ≤ 50000