Sliding Window Maximum | Leetcode
Vložit
- čas přidán 15. 07. 2021
- Check our Website:
In case you are thinking to buy courses, please check below:
Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------------------------------- SDE sheet: bit.ly/takeUforward_SDE
Watch at 1.25x for better experience ..
✅Use coupon-code "TAKEUFORWARD" for getting 15% for all CN courses: aff.codingninjas.com/click?o=...
---------------------------------------------------------------------------------------------------------------------------
Problem Link: leetcode.com/problems/sliding...
C++/Java Code: takeuforward.org/data-structu...
---------------------------------------------------------------------------------------------------------------------------
✅Use coupon-code "STRIVER" for getting 10% on all subscriptions of Unacademy
✅Use coupon-code "TAKEUFORWARD" for getting 10% for all GFG courses: bit.ly/tuf_gfgCourse
✅Please Please SUBSKRIIIBEEEEE the new channel: / @striver_79
---------------------------------------------------------------------------------------------------------------------------
Products that I use:
Best Mic in Affordable Range: amzn.to/3hiTr9p
Yeti mic: amzn.to/3dL4tDF
Boya mic: amzn.to/3h4ROgy
Logitech webcam: amzn.to/3h7d2KI
Cooling pad: amzn.to/3y46pi4
Wacom pad: amzn.to/3xacSIq
Ring light: amzn.to/3y7aaU1
Mic Arm Stand: amzn.to/3qzMuFa
Digitek Green light stand: amzn.to/2U7B3bI
Digitek Stand: amzn.to/363m7Oo
Tripod: amzn.to/35ZmbyT
Office chair: amzn.to/3qysu5Z
Ipad Air: amzn.to/3hjpiXx
Iphone 12: amzn.to/3AavyJV
Watch: amzn.to/3hn7w5A
Macbook Air: amzn.to/363lSTu
Macbook Pro: amzn.to/3qCczDr
Board: amzn.to/3x8GLIO
Mouse: amzn.to/360Asv1
---------------------------------------------------------------------------------------------------------------------------
✅Placement Series: • Let's give back to the...
✅Placement Series (Arrays, Sorting..): • C++ and Java |Brute-Be...
✅Hashing Playlist: • Two Sum Problem | Leet...
✅Greedy Playlist: • N meetings In One Room...
✅Recursion Playlist: • L8. Combination Sum | ...
✅Graph Playlist: • 3 MAJOR ANNOUNCEMENTS ...
✅Two Pointer Playlist: • 3 SUM | Brute | Better...
✅Binary Search Playlist: • Nth Root of a Number U...
✅LinkedList Playlist: • Reverse a Linked List ...
✅Advanced DS playlist: • Fenwick Tree Tutorial ...
✅Stack&Queue Playlist: • Implementation of Stac...
✅Greedy Algorithms: • N meetings In One Room...
---------------------------------------------------------------------------------------------------------------------------
If you appreciate the channel's work, you can join the family: bit.ly/joinFamily
✅Thumbnail Creator: / rikonakhuli
✅ Striver's Linkedin Profile: /
✅ Instagram: /
✅Connect with us: www.google.com/search?client=... (Use Link in Mobile only, if not works search "takeUforward" in telegram)..
##dsa #striver #leetcode
If you understand it, please do like it, and if possible please spare 2 seconds for a comment :)
make videos on dp please
What's the difference between deque and list?
16:22 smaller than equal to is not ok!!
only smaller than will be ok striver.
i don't know why anyone didn't point this out.
@@PrinceKumar-el7ob It would work. Try some test cases.
The best explanation on sliding window
I got this question in a Microsoft interview for SDE 1
Is it offcampus or oncampus
@@kingmaker9082 Off campus
@@zetro6311 from where u applied for Microsoft or have u got any referral? Plz guide me...btw what is the result of interview bro?
@@kingmaker9082 hello bro? which batch are you?
@@vinyass3733 23 batch
This explanation literally made me overcome my fear of stacks and queues. Thank you so much!
Ya exactly..... I also have fear of stack and queue.. Even though they are quite easy to understand.
How one question can over come your fear? 🤔🤔🤔🤔
I couldn't understand this problem's solution even after reading several leetcode discuss posts. However, I understood this completely at once after watching your video! Thanks!
It is always challenging as well as fun to learn the optimal solution. But, your explanation helps a lot to understand it better.
kudos to your patience while explaining sir.The way of you instruct the solution to the problem was quite appealing, unlike some other youtubers who just write the code in rush without explaining properly.
Thanks again
bro getting harsh with apna collegeg
THank you bro.
Brute force+Optimized+code explanation---->complete video.
Thanks a ton.
Good explanation. That's an art which is rare. Every one knows the steps and code and solution, But very few know the explanation and intution
Best Explanation. Thank you so much. Finally understood the use of deque for this problem.
I don’t get the intuition that whenever we remove leftmost index from our window to go to the next window, why the left most index will also be the left most element in the deque (so we just remove the first element from our deque). In my thinking, I should loop through the deque to find the index to remove for every window.
What a explanation 😯...I think this is the best video of window problem in CZcams... Thank you so much for this great video....
Can't find a better explanation than this for a hard problem.. simple love it
Such a Nice Explanation even a beginner can understand. Thanks a lot
easiest solution by naiveApproach
vector maxSlidingWindow(vector arr,int k){//TLE
vector ans;
int n= arr.size();
for (int i = 0; i < n-k+1; i++)
{
ans.push_back(*max_element(arr.begin()+i,arr.begin()+i+k)); // T.C = O(n) max_element
}
return ans;
}
Thanks man I was doubtful about the On complexity. your explanation cleared it :)
Very good explaination , though i have to see it 2 times to completely understand the concept👍
Very great explanation. Thank you bhaiya for helping out the students but I have one suggestion pls upload videos on regular basis. I know u are very busy but it will be helpful for students who are appearing in this placement season. We have found the solution of dse sheet from anywhere but the video explanation of yours is very helpful to remember the concepts and do similar type questions on particular algorithms.
Please increase the frequency of uploads as this is PLACEMENT SEASON
I just had an interview with Google today and this was the algorithm I was given. That's why I'm here Haha. I was able to do it, but I took a different approach.
Waiting for tree series :)
Such an easy explanation, you make it look simple, love it!
Nice explanation your videos are really good...please keep on making such videos...you are doing a great job.
This can also be solved using multiset, can we use multiset in the interview bhaiya?
Understood! Amazing explanation as always, thank you very much!!
Great Explanation ! Thanks for the free quality content
you can do by using a multiset as well , it takes nlogn but its very simple to write the code
what an Explanation...........hats off ✌✌
at 3:48 , deque should be Double ended queues I guess and not doubly linked list , btw nice explanation :)
I think he meant that double-ended queues are typically implemented using doubly linked lists
@@alokesh985 if i am not wrong in doubly linked list one can access,insert and pop elements at any position but in deque one can do it only at front and back
Was waiting for a video on this specific question, thanks a lot
this was very hard for me . thanks for such a good explanation.
I just like every video of yours becuz your's are really gona help.
Godly explanation. Suddenly, this problem does not look Leetcode Hard level
dude!! your explanation is amazing.
Is there any algorithm related to next greatest element or next smallest element, like how to devise algorithms for these type of problems, how to know we need a deque in this case as we do operations on both sides here?
This question can also be solve using heap
Thanks a lot! this was super helpful :)
UNDERSTOOD..........Thank You So Much for this wonderful video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
That definitely not at 5:15 reminds me of Dhoni xD.
great explaination as always.... waiting for more videos
Worst case occurs when k = 1 , Inserting all N element and N-1 elements will be removed. This is because for each array element two operation DELETION -> INSERTION IS PERFORMED .
you are amazing God bless you. I wanna become like you one day
Ur explanation is so awesome.. It's really helpful to us..🙏
can you please upload the video of 862. Leetcode problem Shortest subarray with Sum at Least K.🙏🙏
please sir please I'm really stuck in this problem.
Bhai when your course starts in unacademy pls update waiting for your course
Bro can u please make a video on how to deal with large numbers and what exactly 10^9+7.
Hello Striver, new here, can you tell whether you are covering only this SDE sheet here on any other topics too ? anyone ?
I am brining in series shortly..
I understood the solution!
I got this question in one interview round and also in the written round
bhaiya please bring more videos fast fast .. placements are starting!!
Thank You very much! You explain very well.
Great Explanation
had to watch 2 times to understand this but it was beautiful. thanks
Great explanation!
Understood Thanks Striver , I am suffering from health issues , Still not giving up.
How about using Max Heap with size K.. time complexity will be NLogN i guess.. Space complexity will be O(K)
Nice explanation bro!
good explanation thank you so much
how is i-k the outbound element? at 16:02 ?
it is not working for all the test cases in geeks for geeks
very clear explanation, thanks
Bhaiya please make a video on the question: Find maximum of minimum for all the window sizes.
awesome explanation bro.
all doubts gone
the flow of teaching is amazing bor
Very good explanation, thank you bro
Simply, thank you!
Thankyou So much for such excellent explaination
The part that confuses me is dq.empty() or dq.front(), i thought they return a value at the index not the index itself. So how is it used here that it is checking the index and not the value? I am so confused.
Ur explanation is so awesome.. It's really helpful to us..🙏
can you plzz upload the video of 862. Leeetcode problem Shortest Subarray with Sum at Least K.🙏🙏
please sir please I'm really stuck in this prblm.
Please add heap questions in SDE sheet.
Is the time complexity , really O(n) here ??.... because, if we take example, 6,4,5,3,2 with window size k =3, then once the greatest element 6 is removed, the next greatest element that is 5 should be placed at top, and for doing that worst case, there will be (k-1) comparisons. Anybody please correct me if I am wrong .
can we use max heap??
Great explanation ❤️❤️
the best explanation on yt.
not able to understand the lst part of the i>-=k-1 onwards part
we can do this using queue also, why queue is not used and deque is used?
Waiting for tree series eagerly.
Placement already started in college, and tree , dp, strings remaining from the sheet
*Brute force*
class Solution {
public:
vector maxSlidingWindow(vector& nums, int k) {
vectorans;
int n = nums.size();
for(int i=0; i
It is necessary because no one teach us like you
Genius guy🙌🙌
Thanks!
Great brother 👌👌 keep it up 👆
Thank You!!
This person is gifted
Huge fan of your videos
Could not understand completely, but will come back
thank you striver!
amazing brother
why we should not directly give optimised solution of the particular problem in the interview
Bro please make a video on your jee journey
directly jumped to solution,
Intution is missing... :(
great explanation bhai
I solved it using segment tree
Too good an explanation
understood thanks :)
thanks brother
Nice explanation 👍
Thank you bhaiya ❤️👍
videos are priceless.
👍 Great Bhaiya
A day before the interview at 2x speed.
14:22 ye time complexity O(n-k)+O(k) ni honi chahiye be because hum ans vector bhi to store kar rahe hai plz clear my doubt