The degree of an array is the largest number of times any single value occurs in it. Given nums, find the shortest contiguous subarray whose degree equals the degree of the whole of nums, and return its length.
The degree is 2: both 4 and 7 occur twice. A subarray must hold both copies of one of them to reach that degree. The two 7s sit next to each other, so [7,7] does it in length 2; covering the two 4s would take length 5.
3 occurs three times, at indices 1, 4 and 5, and nothing else occurs that often. The shortest subarray holding all three is [3,5,8,3,3].
Every value occurs once, so the degree is 1 and any single element is enough.
Constraints
1 <= nums.length <= 5 * 10⁴0 <= nums[i] < 5 * 10⁴To match the array's degree, a subarray must contain every copy of some value that occurs that many times. For one value, the shortest such subarray runs from its first copy to its last.
2