Finding the Shortest Subarray with the Same Degree
Initialize three dictionaries: left to store the first occurrence index, right to store the last occurrence index, and count to store the frequency of each element.
Iterate over the array, updating left, right, and count for each element.
Determine the degree of the array, which is the maximum value in count.
Iterate over the elements in count that have a frequency equal to the degree.
For each of these elements, calculate the length of the subarray from its first to last occurrence and update the answer with the minimum length found.