Bro, you literally must have spend a lot of time and efforts for sure because you explain such complex problems with ease ! that even experienced professional tutors aren't able to. Really appreciate your hardwork and contribution. Thanks buddy :)
I was finding the correct explanation from long time. My search ends here and you found a new subscriber. I will keep referring your video. Appreciate your effort you kept in this video, and thank you for helping me out! 🙂
If anyone did not understand why the time was O(2N), it is because, for each element in the array, we at max do only 2 operations: 1. we push it to stack 2. We pop it from the stack. The whole algorithm just does this. So the worst case will be all the elements are pushed and also popped while running the algo. Hence O(2N)
@@techdose4u I would suggest you to make dedicated videos on DP and graphs including medium level questions not just easy one to attract regular views and with easy or general questions u will not attract students for long but with dedicated videos students follows regularly
Thanks Surya for your wonderful explanation! I have a quick question here. How the stack traversal is different brute force traversal? I guess both will take same time...isn't it? For example in brute force technique, we started at 6th Index and traversed all the way till first element. And we did the same thing in stack as well.
here we are removing elements that are smaller than given index i, and after that we are pushing i in the stack, so if we go to next index and if arr[i+1]> arr[i], then we will be sure that the elements that we have removed in the previous step are less that arr[i+1], so we don't have traverse that elements again as they are already removed.
While loop doesn't make the time complexity O(N2). The inner while loop will pop a maximum of N elements combining all the outer loops. Dry to dry run by using any example. You can go to 2N but not N^2.
Can you just use the previous calculations, like "if previous element is less than the current one, look to the left of the lower element's span"? This way you'll reuse the previous calculations and don't need the stack.
Thank you sir for such a nice explanation. I didn’t understand worst time complexity how it come out to be O(N). I believe that it’s O(N^2). Sir could you please help me with time complexity?
sir, plz make video on dynamic programming ......as it is asked more in interview.....make a playlist of DP and upload 2-3 video daily....plz .....i have very less time to prepare for job.
I will keep uploading but the thing is that i make videos whenever i get time. I upload the important questions for interview itself. If you need any help for interview then let me know.
sir, plz make video on dynamic programming ......as it is asked more in interview.....make a playlist of DP and upload 2-3 video daily....plz .....i have very less time to prepare for job.
Bro, you literally must have spend a lot of time and efforts for sure because you explain such complex problems with ease ! that even experienced professional tutors aren't able to. Really appreciate your hardwork and contribution. Thanks buddy :)
I was finding the correct explanation from long time. My search ends here and you found a new subscriber. I will keep referring your video. Appreciate your effort you kept in this video, and thank you for helping me out! 🙂
If anyone did not understand why the time was O(2N), it is because, for each element in the array, we at max do only 2 operations: 1. we push it to stack 2. We pop it from the stack. The whole algorithm just does this. So the worst case will be all the elements are pushed and also popped while running the algo. Hence O(2N)
everyone was complicating it ... I found relief in your solution ... the code at side really helped to visualise !
sir, thank you very much from bottom of my heart. you are putting a lot of effort. your video helps me a lot.
I am glad that students feel the way you do :) This is my motivation
yesterday night i read the book ....i didn't understand ...but after watching your video i got the clear cut idea ..
Thank you very sir.I was searching on youtube regarding this problem watched 2 other videos and stopped here. You made my understanding clear.
Welcome :)
after seeing many vidoes i got good clarity in this thank you bro
Welcome :)
Best video for algo ..
Thanks sir.😊
This video explained the problem very well! Thanks a lot sir
Welcome :)
only this video gives me a clear approach!!
Have you uploaded video on redundant bracket?..I am not getting it
Where u implemented queue and stack for competitive programming. Solution.... coz theres no queue stack in STL
awesome and mind blowing explanation bro , thank u very much 🔥🔥🔥
Thank your for your clear explanation sir....helped a lot!
Welcome :)
Your Explanation technique is awesome. If possible please make more videos related to hashing,backtracking and Strings.
Sure :)
Nice explanation sir
very informative video. Thanks a lot.
can your soln work for input:13,15,12,14,16,8,6,4,10,30
U teaches nice and u do a lot of efforts
Yea it takes a lot of effort to make even a small video :) I am glad you all love it.
@@techdose4u I would suggest you to make dedicated videos on DP and graphs including medium level questions not just easy one to attract regular views and with easy or general questions u will not attract students for long but with dedicated videos students follows regularly
Yes true. It's all about time. As soon as i get time, i make some videos. Will continue with graph soon. I was thinking the same as you suggested.
Thanks for providing these vdos..
Welcome :)
excellent approach sir.loved it
Hi. I don't understand the maximum profile sales wine problem (DP approach). can you make a video on it?
Yea sure.....will make this week :) Thanks for suggesting. If you have a link then do share.
Can you provide a link to the problem. I found wine selling with max profit using DP. Is this the one?
@@techdose4u Thank you.
here is the link,
www.geeksforgeeks.org/maximum-profit-sale-wines/
nice explanation. how did u get a thought that stack is a better data structure for solving this problem? can anyone explain
Thanks Surya for your wonderful explanation!
I have a quick question here. How the stack traversal is different brute force traversal?
I guess both will take same time...isn't it? For example in brute force technique, we started at 6th Index and traversed all the way till first element. And we did the same thing in stack as well.
here we are removing elements that are smaller than given index i, and after that we are pushing i in the stack, so if we go to next index and if arr[i+1]> arr[i], then we will be sure that the elements that we have removed in the previous step are less that arr[i+1], so we don't have traverse that elements again as they are already removed.
so poping element will not make the algo O(N2). I just do not know how come this is O(N)
That's because an element can be popped only once. So max time for popping is also O(N).
@@techdose4u not quite right. you have a while loop which will keep popping till you see a larger element.
While loop doesn't make the time complexity O(N2). The inner while loop will pop a maximum of N elements combining all the outer loops. Dry to dry run by using any example. You can go to 2N but not N^2.
Great Explanation
What is the difference between this problem and online stock problem?
All values are known already here. But online means you see an element at a time without knowing about future :)
U explain so well 😇
marvelous expalantoin sir,thanks a lot ....
Welcome :)
Brilliant explanation
Thanks :)
Can you just use the previous calculations, like "if previous element is less than the current one, look to the left of the lower element's span"?
This way you'll reuse the previous calculations and don't need the stack.
Nice Explanation thanks for the efforts you put to make awsome videos that help lot of people :)
Welcome 😊
Truly appreciable... Very nicely explained. I have subscribed you. Thanks for this video.
Welcome :)
Nice explanation 👌👌👌 bro
Thanks :)
Hi great video!
What software do you use?
openboard
Plz give the code implementation also in c
Excellent explanation. Video highly recommended.
Thanks :)
Nearest greater integer to the left..that's the concept
It takes lots of efforts to make such videos and explain in simplest possible way
This is priceless 👍
Yea it does. Thanks :)
@@techdose4u same code is there in gfg article not more
Thankyou so much, sir!!!
Welcome :)
Amazing
what will the Answer if [100,80,60,70,65,75,85]
1, 1, 1, 2, 1, 4, 6
Thank you sir for such a nice explanation.
I didn’t understand worst time complexity how it come out to be O(N).
I believe that it’s O(N^2).
Sir could you please help me with time complexity?
Traversal of array is done one time, so time complexity is O(N)
Nice one yo
Thanks
Jazakallah khair
Thank you!
Welcome
Thank you sir 🤗
Welcome :)
sir, plz make video on dynamic programming ......as it is asked more in interview.....make a playlist of DP and upload 2-3 video daily....plz .....i have very less time to prepare for job.
When is your interview?
@@techdose4u within 20 days
I will keep uploading but the thing is that i make videos whenever i get time. I upload the important questions for interview itself. If you need any help for interview then let me know.
@@techdose4u ok ,sir
awesome
Thanks :)
before moving to next day i, you forget to tell the part of pushing back the popped elements from another stack till i-1 days.
May have missed.....😅
Thanks sir
Welcome :)
nice
Thanks
vwery nicely ex[lained
Thanks
Thank you so much....
I want to donate for your channel.
Consider your support as a donation :)
Ty brother
sir, plz make video on dynamic programming ......as it is asked more in interview.....make a playlist of DP and upload 2-3 video daily....plz .....i have very less time to prepare for job.
When is your interview?
Have you paid me ? that he'll fully dedicate his time to upload 2-3 videos specifically on DP for you because your interview is coming? Morons -_-