DP 2. Climbing Stairs | Learn How to Write 1D Recurrence Relations

  Рет қаралды 433,117

take U forward

take U forward

Күн бұрын

Lecture Note: takeuforward.org/data-structu...
Problem Link: bit.ly/3t1Sjyx
Make sure to join our telegram group for discussions: linktr.ee/takeUforward
Pre-req for this Series: • Re 1. Introduction to ...
Full Playlist: • Striver's Dynamic Prog...
In this video, we have discussed how to write recurrence relations using the problem of climbing stairs. I have told you three important points which can help you in writing any recurrence relations.
If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.org/interviews/s...
You can also get in touch with me at my social handles: linktr.ee/takeUforward

Пікірлер: 953
@utkarshyadav3401
@utkarshyadav3401 2 жыл бұрын
You say consistency !!! I hear Striver !!!! 😊😊😊 Man you are too good !!!!
@user-bo9br3bo4y
@user-bo9br3bo4y 8 ай бұрын
I finished my engineering and now I m working , came back to listen to the song that gets played for few seconds in last . Good old days.
@MadhavGupta-fi2tu
@MadhavGupta-fi2tu Жыл бұрын
Points to remember: Step1. Identify a DP Problem. Step2. To solve the problem after identification. 1. Try to represent the given problem in terms of index. 2. Do all possible operations on that index according to the problem statement. 3. To count all possible ways - sum of all stuff. To find minimum/maximum - Take Minimum/maximum of all stuff. Understood 🔥🔥🔥
@niteshsaxena1066
@niteshsaxena1066 2 ай бұрын
These steps will work well on leetcode/GFG but not on codeforces For CP, you need to watch priyansh video
@nikhilgupta2569
@nikhilgupta2569 Жыл бұрын
Great work Striver. Just couple of observations since f(n) denotes no of ways to reach nth stair from step 0. It implies f(0) should be 0(you don't have to move at all, you are already at your destination), f(1)=1(because only one step of single jump needed) and f(2) = 2 because in this case either two times a 1-step can be taken or a single 2-step works. So closely this pattern doesn't resemble fibonacci till index 2, because f(2) is not a sum of f(1) and f(0), rather they are adding upto 1. So my logic would be: // JS Snippet const climbStairs = function(n) { const recursion = (i) => { if(i
@vamshisamsetty186
@vamshisamsetty186 Жыл бұрын
Was thinking the same!!
@MP-eq8fx
@MP-eq8fx Жыл бұрын
Thank you Nikhil. You explained it very easily. So I wrote it this way: //JS Snippet function numOfStairs(n) { if (n
@sahillodha6084
@sahillodha6084 Жыл бұрын
Firstly I thought that at f(0) he can't move and over there return 1 indicates that even not moving can be considered as a way but it will be same for entire problem and make it unsolvable but it isn't so you have cleared thank you
@aasifali9139
@aasifali9139 Жыл бұрын
I was thinking the same.. that why is there 1 ways to reach stair 0?
@TIMEe..
@TIMEe.. Жыл бұрын
Your code will fail for 3
@TravelTracksByDebo
@TravelTracksByDebo 2 жыл бұрын
Finally after 7 month because of you bhaiya got to know the intuition behind aolving a DP problem and the patterns too.....fully understood
@dpxy1599
@dpxy1599 2 жыл бұрын
Yess
@manantyagi6905
@manantyagi6905 Жыл бұрын
Bestest stuff of all the cases of tutorials on youtube
@syedakhudsiyatarannum5695
@syedakhudsiyatarannum5695 Жыл бұрын
understood solved the problem on my own just after reading the question thanks to your recursion playlist and 1st video on dp
@GurpreetSingh-ou4wj
@GurpreetSingh-ou4wj 2 жыл бұрын
Understood! earlier was doing it in another way, but today i got a new way of thinking i.e. if we are on nth idx then we have jumped from n-1th and n-2th 🙃
@sukhpreetsingh5200
@sukhpreetsingh5200 Жыл бұрын
Understood! I done this question myself thanks a lot to u for this amazing series
@dharmeshpoladiya9047
@dharmeshpoladiya9047 2 жыл бұрын
Understood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥
@keshav_k_0793
@keshav_k_0793 Жыл бұрын
1. Try to represent any problems in terms of index 2. Do all possible stuffs on that index, according to the problem statement 3. Sum of all stuffs ->count all the ways , min(of all stuffs) -> Find min
@tanishamajumdar3552
@tanishamajumdar3552 Жыл бұрын
points to remember any problem should be broken down to a recursive function. 1. try indexing 2.try writing all possibilities using indexes 3.for finding min /max => count the no. of ways(sum of all f(n))=>min/max(all posssible f(n))
@stith_pragya
@stith_pragya 7 ай бұрын
Understood, Thank You So Much for this wonderful video...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@vishalchoudhary5918
@vishalchoudhary5918 2 жыл бұрын
I struggled hard to get its recursive bit u made it so much easy
@shuvbhowmickbestin
@shuvbhowmickbestin Жыл бұрын
Hi striver, if you're reading this then I'd request you to put this video in the shortened version of this playlist as well since here you're teaching how to encounter problems related to 1D array which is necessary to understand to be able to solve 1D problems on DP.
@Sanya-ic8gr
@Sanya-ic8gr Ай бұрын
UNDERSTOOD! Thank you striver!!
@utkarshaggarwal1631
@utkarshaggarwal1631 Жыл бұрын
I understood this as : to reach the nth stair, you find out the ways to reach the (n-1)th stair (from where you take 1 step to reach nth stair) and the ways to reach the (n-2)th stair (from where you take 2 steps to reach the nth stair), and sum them to get total no. of ways. Is my understanding correct?
@AbdulRahman-tj3wc
@AbdulRahman-tj3wc Жыл бұрын
Absolutely correct
@rashmikareddy3259
@rashmikareddy3259 2 жыл бұрын
Learning to be consistent from you sir.. UNDERSTOOD
@atech_guide
@atech_guide 2 жыл бұрын
Great Explaination in building the recursion. Thanks
@lakshmichandhana
@lakshmichandhana Жыл бұрын
Amazing Lectures ,learnt a lot .Great initiative.
@RAHULKUMAR-sx8ui
@RAHULKUMAR-sx8ui 2 жыл бұрын
if logic is magic then you are a great magician appreciate it sir ❤️
@atharvakalele37
@atharvakalele37 2 жыл бұрын
Do I just need to solve these questions first before attempting anything similar on leetcode or do I need to do both leetcode and your problems both on parallel....btw you are the best teacher I ever learned from...keep on making these videos man...and education would become completely free soon!
@sakshiupadhyay3284
@sakshiupadhyay3284 2 жыл бұрын
More power to you striver... "UNDERSTOOD"
@ekta9145
@ekta9145 Ай бұрын
Understood! Thank you very much, sir.
@yt_ac
@yt_ac 8 ай бұрын
Day - 1 : understood the three points clearly
@lifehustlers164
@lifehustlers164 4 ай бұрын
3/57 done!!! Understood!
@easycode3189
@easycode3189 Жыл бұрын
nderstood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥
@alienx2367
@alienx2367 2 жыл бұрын
Just a suggestion you can cover whole screen by the black board, just a small rectangule for your face at left or right bottom
@takeUforward
@takeUforward 2 жыл бұрын
The iPad screen reso is small. So if I elongate it to the whole screen, it stretches and the colors go off.
@rabindrakumar949
@rabindrakumar949 2 жыл бұрын
Face is not required.
@takeUforward
@takeUforward 2 жыл бұрын
Padhai kar lo, face rhe na rhe usse kya h. 😂
@ManishKumar-qx1kh
@ManishKumar-qx1kh 2 жыл бұрын
@@rabindrakumar949 why r u focusing on the face, just get the knowledge he is sharing for free.
@rabindrakumar949
@rabindrakumar949 2 жыл бұрын
@@ManishKumar-qx1kh I am not able to focus most of the time on actual content due to the face. In Aditya Verma video I like the fully content screen. And about free content, yes we get the content as free and do you think someone in this world will work to provide such valuable content without getting paid. I guess some indirect money must motivating them to provide such incredible content.
@VivekJaviya
@VivekJaviya 2 жыл бұрын
Leetcode daily problem + Codechef daily problem + GFG daily Problem + Striver Daily dp problem = :)
@sakthi6023
@sakthi6023 Жыл бұрын
=Google
@kingmaker9082
@kingmaker9082 Жыл бұрын
So, ur planning to become SDE in Meta 🤙
@VivekJaviya
@VivekJaviya Жыл бұрын
@@kingmaker9082 Meta to nhi but USA ke startup or MNC se offer to mil gaye upar ki chijo se!
@kingmaker9082
@kingmaker9082 Жыл бұрын
@@VivekJaviya bro iam also preparing in the same pattern nd I'm currently studying mca 1st year. Iam looking for ppo's in mncs like Goldmansachs, Amazon, uber etc...could you plz say ur linkedin id?
@Harshanandita
@Harshanandita Жыл бұрын
Are you saying practicing every day or are you talking about the problem which is given everyday on LeetCode and GfG?
@newtonsir6752
@newtonsir6752 2 жыл бұрын
I'm ur new subscribers. Thank u for all the efforts and please continue to do so. Ur lectures are great. Please explain me the base case : Why return 1 ?
@dhrubajyoti3774
@dhrubajyoti3774 2 жыл бұрын
Bcoz there is only one way to reach step 1 from step 0
@vikasbagri1225
@vikasbagri1225 2 жыл бұрын
you can think (n == 0) as you have ultimately reached to your destination i.e. at the nth step and no need to take any more step and thus you can conclude that you have found one of the way to reach the nth stair and hence return 1 indicating that hey I have found one of the possible way to reach the target and you can actually increment the total count of possible ways to reach the nth stair I hope it helps
@somnathroy102
@somnathroy102 Жыл бұрын
This is so simple. Thank you Understood.
@ganapathyg981
@ganapathyg981 2 жыл бұрын
Thanks for explaining in English.. love from Tamilnadu 😎
@nimsguy
@nimsguy Жыл бұрын
Thanks for the explanation and whole series!. Shouldn't base case be if(index === 0) return 0 ?. If this is right, then when n=3, we will have only 2 possible ways to reach step 3 which is incorrect ?.
@karansumbly1254
@karansumbly1254 Жыл бұрын
We are not counting the number of steps but the number of ways. So as soon as the function hits 0, we can say that we have found a new way and hence return 1.
@sakshisinghal1669
@sakshisinghal1669 2 жыл бұрын
I am unable to understand why we need 1 to jump to same stair that is from 0->0 (base case)? According to me it should be zero. Correct me if I am wrong.
@sandeepdeepu5052
@sandeepdeepu5052 Жыл бұрын
I too didn't understood in the beginning but after sometime I figured out that = see you are coming from n to reach 0 which means there is way from n to our destination '0' so you return 1 saying that there is a possible way from n to reach 0 so it is returning true. You should not think like from 0 to 0 there is no way then why i am returning 1. You have think from the given "n' perspective. because 0 is the last index to get on so if we get to the last index we found out a way from n. So when we reach to 0 index we are saying to n that " hello n there is a possible path from u".
@kaushikmahanta6463
@kaushikmahanta6463 Жыл бұрын
@@sandeepdeepu5052 thank u
@sandeepdeepu5052
@sandeepdeepu5052 Жыл бұрын
@@kaushikmahanta6463 felt happy that you understood my explanation.
@AyushRaj-sx6ju
@AyushRaj-sx6ju 2 жыл бұрын
Kudos to your effort striver ❣
@gurveer1527
@gurveer1527 2 жыл бұрын
int countDistinctWays(int nStairs) { //DP Tabulation solution int mod = 1000000007; vectorDP(nStairs+2, -1); //Initial Steps DP[0] = 1; DP[1] = 1; for(int i= 2; i
@shreyanshgupta6163
@shreyanshgupta6163 Жыл бұрын
Why you took nstairs+ 2 istead off nstairs +1?
@ranjannitjsr533
@ranjannitjsr533 Жыл бұрын
​@@shreyanshgupta6163it should be n+1
@punitgarg4627
@punitgarg4627 2 жыл бұрын
one small mistake ,for idx==1, return 1 aayega instead of 0, nicee explanation sir❤❤
@035asadali8
@035asadali8 2 жыл бұрын
he mentioned in video ,u missed
@ratinderpalsingh5909
@ratinderpalsingh5909 2 жыл бұрын
Understood, sir. Thank you very much.
@lavakumar3243
@lavakumar3243 10 ай бұрын
The first thought It came to my mind was permutation and approached like permutation with repetition, but it gave timeout for test cases after n=30.
@ketanahuja8939
@ketanahuja8939 2 жыл бұрын
At 7:25 , it will be return 0 when (ind==0)
@shreyanshpatil8303
@shreyanshpatil8303 2 жыл бұрын
no it will be 1
@siddharthb2226
@siddharthb2226 2 жыл бұрын
yaara ne
@karanjitsinghrandhawa445
@karanjitsinghrandhawa445 2 жыл бұрын
Bhaiya I am currently learning c++ by this month I will complete all fundamentals of c++ Please bhaiya can you suggest me where to start DSA as a beginner ????? Please bhaiya reply Love from Guwahati ❤️
@AbhishekSingh-kt8fi
@AbhishekSingh-kt8fi 2 жыл бұрын
For DSA in cpp check out dsa playlist from simple snippet!
@harshitparashar
@harshitparashar 2 жыл бұрын
Abdul bari
@karanjitsinghrandhawa445
@karanjitsinghrandhawa445 2 жыл бұрын
@@AbhishekSingh-kt8fiso means after c++ i can start with simple snippet???
@karanjitsinghrandhawa445
@karanjitsinghrandhawa445 2 жыл бұрын
@@harshitparashar for beginners will it be good???
@harshitparashar
@harshitparashar 2 жыл бұрын
@@karanjitsinghrandhawa445 yup
@likhitbhogadi
@likhitbhogadi 7 ай бұрын
thanks bro, understood..
@aagamjain2131
@aagamjain2131 Жыл бұрын
Awesome explanation!! Understood sir 🔥💯
@devanshkumar3816
@devanshkumar3816 2 жыл бұрын
understood! but one confusion... shouldn't it be "if(ind == 0) return 0; " as we are left with no way to reach to the end when ind equals 0 !
@rohalkurup1350
@rohalkurup1350 2 жыл бұрын
remember as if for standing in the same place there is one way , logically speaking there is no way , but if we are considering the problem here it will be 1
@suhailansari3847
@suhailansari3847 2 жыл бұрын
@@rohalkurup1350 how 1?
@akshaydeshmukh5390
@akshaydeshmukh5390 2 жыл бұрын
You are right. It should be 0 as we have already reached the destination and don't need to move any further. You can write separate base case like if (index
@nimsguy
@nimsguy Жыл бұрын
@@rohalkurup1350 but is it kind of confusing ?. because at step 1, yes there is one way to reach step 0, but at step 0, there is no way to reach as it is already reached. bit confusing this part is. :-(
@avtarchandra2407
@avtarchandra2407 2 жыл бұрын
Kudos to your effort striver ❣️
@shivammishra2413
@shivammishra2413 Ай бұрын
understod.thanks striver bhaiya ❤
@shivanshumishra0560
@shivanshumishra0560 Жыл бұрын
Understood !!! really awesome explaination........
@perveenneha1423
@perveenneha1423 2 жыл бұрын
understood heart felt thank you
@prathyushabuddarapu314
@prathyushabuddarapu314 2 жыл бұрын
UNDERSTOOD SIR...! Thank you
@SwapnilChavan-im7xh
@SwapnilChavan-im7xh Жыл бұрын
Understood 🔥🔥🔥 Thanks for Your teachings
@suryashjha7892
@suryashjha7892 2 жыл бұрын
Amazing explanation 🔥🔥🔥
@AnitaSharma-bk4fc
@AnitaSharma-bk4fc 15 күн бұрын
Understood thanks striver❤
@vakhariyajay2224
@vakhariyajay2224 Жыл бұрын
Thank you very much. You are a genius.
@amitpawar8035
@amitpawar8035 2 жыл бұрын
Awesome explanation as always
@ritikasingh7252
@ritikasingh7252 2 жыл бұрын
Awesome explanation👏
@desihiphop4998
@desihiphop4998 2 жыл бұрын
Understood !!!!!!!! Fully sasfied !!!!!!!
@addityasharma6426
@addityasharma6426 2 жыл бұрын
understood, great explanation bhaiya😊😊😊
@komalkrishna7836
@komalkrishna7836 2 жыл бұрын
Understood... Thank you!
@rahulreddy3588
@rahulreddy3588 11 ай бұрын
Understood very well!👌
@user-ym1nv1pw8i
@user-ym1nv1pw8i Ай бұрын
Understood! Mark for revision!
@nirban7689
@nirban7689 2 жыл бұрын
//You are a really good teacher. Respect++;
@thenriquevicentini
@thenriquevicentini 3 ай бұрын
Understood, thanks!
@052_a_sourabhpathak5
@052_a_sourabhpathak5 Жыл бұрын
Damn , this is what tier 3 college should teach in DSA's classess!
@deepakabari17
@deepakabari17 Жыл бұрын
Very well understood 👏👏
@sunildhiman90
@sunildhiman90 10 ай бұрын
Hi Striver @takeUforward, one question here, As you said previously if we need to find all possible ways then we try recursion and backtracking, Here again we are saying same thing. So does it mean dp is just the optimized way of solving backtracking problems with time and space both optimized?
@DPCODE72
@DPCODE72 2 жыл бұрын
Now I would believe in myself that I will be selected as A SDE in Amazon soon. Bhaiya with ur support & help.
@chahakjain6787
@chahakjain6787 Жыл бұрын
very easy explanation sir!!
@aditianand6966
@aditianand6966 10 ай бұрын
thank you for making such a good content
@ratnak5370
@ratnak5370 2 жыл бұрын
FULLY UNDERSTOOD
@priyatamkumar518
@priyatamkumar518 2 жыл бұрын
understood , a lot of wishes for you
@raghavmanish24
@raghavmanish24 Ай бұрын
uunderstood.....thanku striver
@NazeerBashaShaik
@NazeerBashaShaik 8 ай бұрын
Thank you!
@roydebraj2188
@roydebraj2188 19 күн бұрын
did it myself feels soo godd hehe
@creativeprojects217
@creativeprojects217 5 ай бұрын
thank you sir❣
@dheerajshukla7008
@dheerajshukla7008 Ай бұрын
understood bhaiya
@rtadwq...------...----.
@rtadwq...------...----. 2 жыл бұрын
Nicely explained sir
@vedantsharma2921
@vedantsharma2921 2 жыл бұрын
how much time should i give to complete this playlist considering I have placements in 1 month?
@amalasebastian9968
@amalasebastian9968 11 ай бұрын
Liked the video even before starting it..Obviously its made by Striver ,it had to be great❤
@natashadale6333
@natashadale6333 2 жыл бұрын
Good job 💙🌼
@riderpd09
@riderpd09 2 жыл бұрын
OP explanation BHaiya!!
@Aladin40chor
@Aladin40chor 9 ай бұрын
Understood 👑
@akshitmangotra5370
@akshitmangotra5370 Жыл бұрын
understood! Thanks!!
@GhostVaibhav
@GhostVaibhav 4 ай бұрын
Understood🔥
@mohitagarwal1888
@mohitagarwal1888 2 жыл бұрын
This is your only video till now that i didnt understood .
@shyren_more
@shyren_more 2 жыл бұрын
understood, thanks!
@sparshsharma3150
@sparshsharma3150 2 жыл бұрын
Understood bhaiya! 🔥
@drishtirai864
@drishtirai864 5 ай бұрын
Understood ..!!
@arihantjammar8888
@arihantjammar8888 9 ай бұрын
Understood 😊
@deepanshudhakate9622
@deepanshudhakate9622 2 жыл бұрын
UNDERSTOOD 🔥🔥
@jayantmishra6897
@jayantmishra6897 2 жыл бұрын
bhayia your way of teaching is amazing.one thing i want to ask you that from where did you learned all these.
@Shivi32590
@Shivi32590 21 күн бұрын
thank you
@tango2olo
@tango2olo Жыл бұрын
From step N-1 there is only 1 way to reach Nth step i.e. a 1-step jump. But from step N-2 there are 2 ways to reach step N, 2 1-step Jump and 1 2-step jump. So the recursion shall be Sol(N) = [Sol(N-1)*1] + [Sol(N-2)*2]; because for each Sol(N-2) we have 2 ways to reach Sol(N).
@user-ip7ov5ne8l
@user-ip7ov5ne8l 3 ай бұрын
Understood ❤
@user-ug4sl4gf2x
@user-ug4sl4gf2x 21 күн бұрын
Understood 💯
@genzScarlet
@genzScarlet 5 күн бұрын
UNDERSTOOD :)
@siddheshborse3536
@siddheshborse3536 Жыл бұрын
Not getting feeling of Solution.... but understood the shortcut very well... thank you😀
@amanbhadani8840
@amanbhadani8840 2 жыл бұрын
Can anyone tell me ,can we think of solving this problem just like combination sum 1 problem by taking array having element as 1 and 2.I know it would not be optimal but i am just having a thought??
@adebisisheriff159
@adebisisheriff159 7 ай бұрын
Understood!
@souravsarkar6107
@souravsarkar6107 2 жыл бұрын
Understood thank you sir
@rupampal07
@rupampal07 Жыл бұрын
Awesome video "UNDERSTOOD"
DP 3. Frog Jump | Dynamic Programming | Learn to write 1D DP
38:50
take U forward
Рет қаралды 500 М.
The Joy of Computing using Python Week 1 NPTEL Answers
2:18
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 20 МЛН
Scary Teacher 3D Nick Troll Squid Game in Brush Teeth White or Black Challenge #shorts
00:47
Каха и суп
00:39
К-Media
Рет қаралды 6 МЛН
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
80 Year Olds Share Advice for Younger Self
12:22
Sprouht
Рет қаралды 1,3 МЛН
Remote Software Developer Makes 4 Crores/Yr 🔥 ft. @harkirat1
25:49
VICKY KAUSHAL REACTS TO VICKY KAUSHAL MEMES ft. VICKY KAUSHAL
26:42
Tanmay Bhat
Рет қаралды 5 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Climbing Stairs
5:35
Kevin Naughton Jr.
Рет қаралды 99 М.
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 20 МЛН