Skip to content

Commit ac93850

Browse files
committed
1574
1 parent c219f5f commit ac93850

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Nov-15-24.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def findLengthOfShortestSubarray(self, arr: List[int]) -> int:
3+
n = len(arr)
4+
l,r = 0,n-1
5+
while l<n-1 and arr[l]<=arr[l+1]:
6+
l += 1
7+
while r>0 and arr[r]>=arr[r-1]:
8+
r -= 1
9+
if l>=r:
10+
return 0
11+
ans = min(n-l-1,r)
12+
i = 0
13+
j = r
14+
while i<=l and j<n:
15+
if arr[i]<=arr[j]:
16+
ans = min(ans,j-i-1)
17+
i += 1
18+
else:
19+
j += 1
20+
return ans

0 commit comments

Comments
 (0)