Stock span problem

  Рет қаралды 50,130

Techdose

Techdose

Күн бұрын

This video explains the stock span problem in the simplest way possible. First i have explained the intuitive approach of solving using bruteforce in O(N2) time and then i have shown the intuition behind efficient approach and solved it using stack in just O(N) time. The CODE LINK for the efficient approach is given below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
CODE LINK: gist.github.co...

Пікірлер: 103
@contactdi8426
@contactdi8426 3 жыл бұрын
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 :)
@vikalpjain1098
@vikalpjain1098 2 жыл бұрын
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! 🙂
@abhijeetvdsh
@abhijeetvdsh Жыл бұрын
everyone was complicating it ... I found relief in your solution ... the code at side really helped to visualise !
@aditya4707
@aditya4707 4 жыл бұрын
Thank you very sir.I was searching on youtube regarding this problem watched 2 other videos and stopped here. You made my understanding clear.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@harshpatel1385
@harshpatel1385 5 жыл бұрын
sir, thank you very much from bottom of my heart. you are putting a lot of effort. your video helps me a lot.
@techdose4u
@techdose4u 5 жыл бұрын
I am glad that students feel the way you do :) This is my motivation
@KRajesh-ej7dy
@KRajesh-ej7dy Жыл бұрын
after seeing many vidoes i got good clarity in this thank you bro
@techdose4u
@techdose4u Жыл бұрын
Welcome :)
@PRUTHVIRAJRGEEB
@PRUTHVIRAJRGEEB 4 жыл бұрын
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)
@karanroy-vr1wn
@karanroy-vr1wn 5 жыл бұрын
yesterday night i read the book ....i didn't understand ...but after watching your video i got the clear cut idea ..
@davidjonson303
@davidjonson303 Жыл бұрын
Best video for algo .. Thanks sir.😊
@suvodeepsinha200
@suvodeepsinha200 4 жыл бұрын
This video explained the problem very well! Thanks a lot sir
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@anand__346
@anand__346 2 жыл бұрын
awesome and mind blowing explanation bro , thank u very much 🔥🔥🔥
@digitechtalks4167
@digitechtalks4167 2 жыл бұрын
only this video gives me a clear approach!!
@vibes.productive
@vibes.productive 3 жыл бұрын
Thank your for your clear explanation sir....helped a lot!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@soumensinha305
@soumensinha305 5 жыл бұрын
Your Explanation technique is awesome. If possible please make more videos related to hashing,backtracking and Strings.
@techdose4u
@techdose4u 5 жыл бұрын
Sure :)
@vishekkumar8371
@vishekkumar8371 3 жыл бұрын
Nice Explanation thanks for the efforts you put to make awsome videos that help lot of people :)
@techdose4u
@techdose4u 3 жыл бұрын
Welcome 😊
@GhostRider....
@GhostRider.... 2 жыл бұрын
Nice explanation sir
@praveensisodia8055
@praveensisodia8055 4 жыл бұрын
Truly appreciable... Very nicely explained. I have subscribed you. Thanks for this video.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@kushalhu7189
@kushalhu7189 3 жыл бұрын
Great Explanation
@balramchaudhary6449
@balramchaudhary6449 3 жыл бұрын
very informative video. Thanks a lot.
@abhiram3275
@abhiram3275 3 жыл бұрын
excellent approach sir.loved it
@awakashsinha9926
@awakashsinha9926 5 жыл бұрын
U teaches nice and u do a lot of efforts
@techdose4u
@techdose4u 5 жыл бұрын
Yea it takes a lot of effort to make even a small video :) I am glad you all love it.
@awakashsinha9926
@awakashsinha9926 5 жыл бұрын
@@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
@techdose4u
@techdose4u 5 жыл бұрын
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.
@shreyajoshi5148
@shreyajoshi5148 3 жыл бұрын
U explain so well 😇
@prasad.patil12
@prasad.patil12 4 жыл бұрын
It takes lots of efforts to make such videos and explain in simplest possible way This is priceless 👍
@techdose4u
@techdose4u 4 жыл бұрын
Yea it does. Thanks :)
@jagankumarpatra
@jagankumarpatra 2 жыл бұрын
@@techdose4u same code is there in gfg article not more
@ShivamSingh-me1nb
@ShivamSingh-me1nb 4 жыл бұрын
Brilliant explanation
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@Legendary-Akshit
@Legendary-Akshit 4 жыл бұрын
Excellent explanation. Video highly recommended.
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@rahulchaubey8988
@rahulchaubey8988 5 жыл бұрын
Thanks for providing these vdos..
@techdose4u
@techdose4u 5 жыл бұрын
Welcome :)
@srajsekhar4061
@srajsekhar4061 5 жыл бұрын
Nice explanation 👌👌👌 bro
@techdose4u
@techdose4u 5 жыл бұрын
Thanks :)
@diveshrajput572
@diveshrajput572 4 жыл бұрын
marvelous expalantoin sir,thanks a lot ....
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@sureshgarine
@sureshgarine 3 жыл бұрын
nice explanation. how did u get a thought that stack is a better data structure for solving this problem? can anyone explain
@ahmedmohammedshahid1007
@ahmedmohammedshahid1007 2 жыл бұрын
Amazing
@davidjonson303
@davidjonson303 Жыл бұрын
Have you uploaded video on redundant bracket?..I am not getting it
@MrDheeraj14
@MrDheeraj14 2 жыл бұрын
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.
@gandhijainamgunvantkumar6783
@gandhijainamgunvantkumar6783 2 жыл бұрын
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.
@dmitrykarpenko2271
@dmitrykarpenko2271 4 жыл бұрын
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.
@saisatyanarayanarawi2404
@saisatyanarayanarawi2404 4 жыл бұрын
Nice one yo
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@amirsalih4459
@amirsalih4459 3 жыл бұрын
What is the difference between this problem and online stock problem?
@techdose4u
@techdose4u 3 жыл бұрын
All values are known already here. But online means you see an element at a time without knowing about future :)
@aryan7069_
@aryan7069_ 2 жыл бұрын
Where u implemented queue and stack for competitive programming. Solution.... coz theres no queue stack in STL
@priyankapardesiramachander871
@priyankapardesiramachander871 3 жыл бұрын
Thank you!
@techdose4u
@techdose4u 3 жыл бұрын
Welcome
@mohitdeo3648
@mohitdeo3648 3 жыл бұрын
can your soln work for input:13,15,12,14,16,8,6,4,10,30
@rahulshrivastava3040
@rahulshrivastava3040 4 жыл бұрын
so poping element will not make the algo O(N2). I just do not know how come this is O(N)
@techdose4u
@techdose4u 4 жыл бұрын
That's because an element can be popped only once. So max time for popping is also O(N).
@rahulshrivastava3040
@rahulshrivastava3040 4 жыл бұрын
@@techdose4u not quite right. you have a while loop which will keep popping till you see a larger element.
@techdose4u
@techdose4u 4 жыл бұрын
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.
@akanshapanchal7107
@akanshapanchal7107 4 жыл бұрын
Thankyou so much, sir!!!
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@srilekha9177
@srilekha9177 5 жыл бұрын
Hi. I don't understand the maximum profile sales wine problem (DP approach). can you make a video on it?
@techdose4u
@techdose4u 5 жыл бұрын
Yea sure.....will make this week :) Thanks for suggesting. If you have a link then do share.
@techdose4u
@techdose4u 5 жыл бұрын
Can you provide a link to the problem. I found wine selling with max profit using DP. Is this the one?
@srilekha9177
@srilekha9177 5 жыл бұрын
@@techdose4u Thank you. here is the link, www.geeksforgeeks.org/maximum-profit-sale-wines/
@sahej97
@sahej97 4 жыл бұрын
Hi great video! What software do you use?
@thexhist3609
@thexhist3609 3 жыл бұрын
openboard
@BECSAQUIB
@BECSAQUIB 3 жыл бұрын
Jazakallah khair
@dheerajpoonia2175
@dheerajpoonia2175 5 жыл бұрын
Thank you sir 🤗
@techdose4u
@techdose4u 5 жыл бұрын
Welcome :)
@Inndjkaawed2922
@Inndjkaawed2922 2 жыл бұрын
Nearest greater integer to the left..that's the concept
@RaushanKumar-co3wj
@RaushanKumar-co3wj 4 жыл бұрын
awesome
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@lipishah474
@lipishah474 4 жыл бұрын
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?
@kapilkungwani8025
@kapilkungwani8025 4 жыл бұрын
Traversal of array is done one time, so time complexity is O(N)
@Uzmasamreen29
@Uzmasamreen29 3 ай бұрын
Plz give the code implementation also in c
@prachisingh9868
@prachisingh9868 4 жыл бұрын
nice
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@yatri6329
@yatri6329 3 жыл бұрын
what will the Answer if [100,80,60,70,65,75,85]
@GhostRider....
@GhostRider.... 2 жыл бұрын
1, 1, 1, 2, 1, 4, 6
@shigo6350
@shigo6350 4 жыл бұрын
Thank you so much....
@uttampandey1389
@uttampandey1389 3 жыл бұрын
vwery nicely ex[lained
@techdose4u
@techdose4u 3 жыл бұрын
Thanks
@gtbaba123
@gtbaba123 2 жыл бұрын
Ty brother
@karanroy-vr1wn
@karanroy-vr1wn 5 жыл бұрын
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.
@techdose4u
@techdose4u 5 жыл бұрын
When is your interview?
@karanroy-vr1wn
@karanroy-vr1wn 5 жыл бұрын
@@techdose4u within 20 days
@techdose4u
@techdose4u 5 жыл бұрын
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.
@karanroy-vr1wn
@karanroy-vr1wn 5 жыл бұрын
@@techdose4u ok ,sir
@nikunjgupta2878
@nikunjgupta2878 4 жыл бұрын
Thanks sir
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@mohnishsinghbhamra
@mohnishsinghbhamra 4 жыл бұрын
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.
@techdose4u
@techdose4u 4 жыл бұрын
May have missed.....😅
@harshpatel1385
@harshpatel1385 5 жыл бұрын
I want to donate for your channel.
@techdose4u
@techdose4u 5 жыл бұрын
Consider your support as a donation :)
@karanroy-vr1wn
@karanroy-vr1wn 5 жыл бұрын
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.
@techdose4u
@techdose4u 5 жыл бұрын
When is your interview?
@contactdi8426
@contactdi8426 3 жыл бұрын
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 -_-
L15. Stock Span Problem | Stack and Queue Playlist
19:21
take U forward
Рет қаралды 38 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Largest rectangle in Histogram | Leetcode #84
27:43
Techdose
Рет қаралды 112 М.
Counting inversions in an array
19:03
Techdose
Рет қаралды 94 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 566 М.
Longest increasing subsequence
20:44
Techdose
Рет қаралды 130 М.
Search in rotated sorted array | Leetcode #33
13:52
Techdose
Рет қаралды 84 М.
Online Stock Span - Leetcode 901 - Python
15:19
NeetCode
Рет қаралды 35 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
6 Stock Span Problem
28:02
Aditya Verma
Рет қаралды 224 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН