File tree 1 file changed +13
-0
lines changed
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1
1
import collections
2
2
3
+ # O(n)
4
+ # initialize list to represent list of maximum number in sliding window
5
+ # we initialize a queue for setting the max in sliding window at partcular iteration
6
+ # initialize the left and right pointer at 0 since we are using while
7
+ # while right pointer is less than length of list (setting the boundary)
8
+ # then we need to add the current index to queue
9
+ # if there are value in queue and queue value is less than current, we pop the queue
10
+ # then insert current value
11
+ # if our window is out of bounds remove the leftmost value (end of cur iter)
12
+ # if our loop is equal to sliding wiwndow size 'k' then append the max value(leftmost) and increase
13
+ # left pointer by 1
14
+ # we need to increase r by 1 in every iteration
15
+
3
16
4
17
class Solution :
5
18
def maxSlidingWindow (self , nums : list [int ], k : int ) -> list [int ]:
You can’t perform that action at this time.
0 commit comments