Back to course home
0% completed
Vote For New Content
I think there's a less complex way still using queue.
Tony Pham
Oct 3, 2024
Here's my solution to this.
def max_subarray(arr, k): dq = deque() result = [] for end in range(len(arr)): if dq and dq[0] == end - k: dq.popleft() while dq and arr[dq[-1]] <= arr[end]: dq.pop() dq.append(end) if end >= k - 1: result.append(arr[dq[0]]) return result
0
0
Comments
Comments
On this page