I have the other solution but the complexity is same : class Solution: def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: queue = deque() count = 0 output = [] for i in range(len(nums)): if len(queue) == 0: queue.append(nums[i]) else: while len(queue) != 0 and queue[-1] < nums[i]: queue.pop() queue.append(nums[i]) count += 1 if count == k: output.append(queue[0]) if nums[(i + 1) - k] == queue[0]: queue.popleft() count -= 1 return output
If you do nums[i-k], it equals the front of the deque. That means we moved to the next window. Do it by yourself for the last window, you will understand.
I have seen striver video solution as well, but this explanation tells us the intuition, which is rarely seen in any youtube videos. Hats off to you.
Best Explanation(from introducing new data structure)
Better then all other explanation on youtube , that i seen sofar
maam is the best ....watch 5-6 video but didnt get this type of explainaion and so slowly and calm every step ...thankyou
Nice explanation, clear visual representations, and impressive coding skills. Much appreciated! Thanks:)
In beginning of video I got the vibe that this is the best explanation.. 💯💯💯
Got it. Thanks for this video and for putting so much effort into explaining the answer using an interactive board. It's worth it!!
I tried many videos to understand, but this helped me finally, thanks for ur efforts .
This is the real gem of TH-cam❤❤❤❤
Great video and visual representation
One of the best explanation.. thankyou so much😊
Great explanation . I always wanted someone to explain algo steps while coding also thanks again 🙏🙏
Best Explanation so far for this problem :)
best explanation.came here after watching 2 3 videos for the same question. Thanks for the video!
like srrly i have visited the websites and YT video but not understanding at the last by ur video i have understood thankkkkkkkkk youuuuuuuuu
Very nice explanation..
you're the best. You always provide the best explanation 🙏🙏
Really very good explanation .thank you so much❤❤
much better explanation than striver
Seen 3 explanation and this better than all
One of the best explanation.
after seeing your explanation understood something thank you
Best of whole youtube
you deserve a like I was not able to understand this saw adiitya verma video twice
Thanks a lot for the intuition
maam you are best. Thank you for your effort.
Thank you for this great explanation :)
Amazing explanation!!
Great explanation ❣️
Best Explaination :)
thanks! nicely explained!
grt, grt, grt
grt=great !
veery well explained...
3:56 how can we use Linked List Data Structure here?
Great explanation💖
Best explaination
I have the other solution but the complexity is same : class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
queue = deque()
count = 0
output = []
for i in range(len(nums)):
if len(queue) == 0:
queue.append(nums[i])
else:
while len(queue) != 0 and queue[-1] < nums[i]:
queue.pop()
queue.append(nums[i])
count += 1
if count == k:
output.append(queue[0])
if nums[(i + 1) - k] == queue[0]:
queue.popleft()
count -= 1
return output
very nice explanation di
proper explanation !!
Very very thanks didi..
thanks dude
class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
queue = deque()
count = 0
output = []
for i in range(len(nums)):
if len(queue) == 0:
queue.append(nums[i])
else:
while len(queue) != 0 and queue[-1] < nums[i]:
queue.pop()
queue.append(nums[i])
count += 1
if count == k:
output.append(queue[0])
if nums[(i + 1) - k] == queue[0]:
queue.popleft()
count -= 1
return output
Single for loop code
Love uhh mam❤️
thanku didi
thanks
Best
Can we use set instead of deque?
set can't be modified isn't it?
This code is showing error
Yes bro it's showing an error. Please provide correct code mam
[4,3,11],k=3
showing wrong answer
Lallontop ❤
why i-k in line no. 21
Same question
it's coz if the current max element(front) is present in the previous subarray as well ,so that means we have to delete/remove that element . gotcha?
If you do nums[i-k], it equals the front of the deque. That means we moved to the next window.
Do it by yourself for the last window, you will understand.