```
def find_unsorted_subarray(nums):
l = 0
r = len(nums)-1
max_len = 0
while l<r:
if nums[l+1]<nums[l]:
# l+=1
break
l+=1
if l<r:
while r>l:
if nums[r]>nums[r-1]:
break
r-=1
max_ele = max(nums[l:r+1])
min_ele = min(nums[l:r+1])
start = 0
end = len(nums)-1
while l>start and r<end:
if nums[l-1]>min_ele:
l-=1
if nums[r+1]<max_ele:
r+=1
max_len = r-l
return max_len
```

Why am I getting timeout error for test case:

87

0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9