Back to course home
0% completed
Vote For New Content
def shortest_window_sort(arr): if len(arr) < 2: return 0 start,end= -1,-2 ...
Ike Nwankwo
Mar 8, 2023
def shortest_window_sort(arr): if len(arr) < 2: return 0
start,end= -1,-2 high_num = arr[0] for i in range(1,len(arr)): if arr[i] >= high_num: high_num = arr[i] else: start = i - 1 if start == -1 else start while start > 0 and arr[i] < arr[start - 1]: start -=1 end = i return end-start+1
this is my solution. This is also O(N) correct?
0
0
Comments
Comments
On this page