Shortest Subarray With the Full Degree
Problem statement
The degree of an array is the largest frequency of any value. Return the length of the shortest contiguous subarray having the same degree as nums.
Function
findShortestSubarray(nums: int[]) → intExamples
Example 1
nums = [1,2,2,3,1]return = 2Case 1 exercises the documented deterministic contract.
Example 2
nums = [1,2,2,3,1,4,2]return = 6Case 2 exercises the documented deterministic contract.
Example 3
nums = [1]return = 1Case 3 exercises the documented deterministic contract.
Constraints
1 <= nums.length <= 200000.-10^9 <= nums[i] <= 10^9.