```
def findShortestSubArray(self, A):
"""
:type nums: List[int]
:rtype: int
"""
from collections import Counter
n=len(A)
mp=Counter(A)
degree=0
for key in mp:
degree=max(degree,mp[key])
i,j=0,0
mp2={}
res=n+1
while j<n:
mp2[A[j]]=mp2.get(A[j],0)+1
if mp2[A[j]]==degree:
res=min(res,j-i+1)
while A[i]!=A[j]:
mp2[A[i]]-=1
i+=1
res=min(res,j-i+1)
j+=1
return res
```