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

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 พ.ย. 2024

ความคิดเห็น • 1K

  • @utkarshyadav3401
    @utkarshyadav3401 2 ปีที่แล้ว +279

    You say consistency !!! I hear Striver !!!! 😊😊😊 Man you are too good !!!!

  • @ArathiK-s8u
    @ArathiK-s8u ปีที่แล้ว +50

    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.

    • @parthdurgude2617
      @parthdurgude2617 2 หลายเดือนก่อน +1

      yeahh I too love to listen to it...

    • @adityagaur4686
      @adityagaur4686 หลายเดือนก่อน

      How do u get the job bruh

    • @Abhinav-b2k
      @Abhinav-b2k หลายเดือนก่อน

      @@adityagaur4686 Not everyone is a doofus like you, doing dsa only wont get u anywhere

  • @nikhilgupta2569
    @nikhilgupta2569 ปีที่แล้ว +91

    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 ปีที่แล้ว +4

      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 ปีที่แล้ว +4

      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.. ปีที่แล้ว +1

      Your code will fail for 3

  • @utkarshaggarwal1631
    @utkarshaggarwal1631 2 ปีที่แล้ว +42

    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?

  • @TravelTracksByDebo
    @TravelTracksByDebo 2 ปีที่แล้ว +15

    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

  • @GurpreetSingh-ou4wj
    @GurpreetSingh-ou4wj 2 ปีที่แล้ว +8

    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 🙃

  • @keshav_k_0793
    @keshav_k_0793 ปีที่แล้ว +19

    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

  • @shuvbhowmickbestin
    @shuvbhowmickbestin ปีที่แล้ว +5

    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.

  • @syedakhudsiyatarannum5695
    @syedakhudsiyatarannum5695 ปีที่แล้ว +5

    understood
    solved the problem on my own just after reading the question thanks to your recursion playlist and 1st video on dp

  • @tanishamajumdar3552
    @tanishamajumdar3552 ปีที่แล้ว +5

    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))

  • @manantyagi6905
    @manantyagi6905 2 ปีที่แล้ว +3

    Bestest stuff of all the cases of tutorials on youtube

  • @yt_ac
    @yt_ac ปีที่แล้ว +3

    Day - 1 : understood the three points clearly

  • @vishalchoudhary5918
    @vishalchoudhary5918 2 ปีที่แล้ว +3

    I struggled hard to get its recursive bit u made it so much easy

  • @alienx2367
    @alienx2367 2 ปีที่แล้ว +45

    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 ปีที่แล้ว +38

      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 ปีที่แล้ว +8

      Face is not required.

    • @takeUforward
      @takeUforward  2 ปีที่แล้ว +74

      Padhai kar lo, face rhe na rhe usse kya h. 😂

    • @ManishKumar-qx1kh
      @ManishKumar-qx1kh 2 ปีที่แล้ว +10

      @@rabindrakumar949 why r u focusing on the face, just get the knowledge he is sharing for free.

    • @rabindrakumar949
      @rabindrakumar949 2 ปีที่แล้ว +3

      @@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.

  • @stith_pragya
    @stith_pragya 10 หลายเดือนก่อน +6

    Understood, Thank You So Much for this wonderful video...🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 ปีที่แล้ว +7

    Understood! I done this question myself thanks a lot to u for this amazing series

  • @lavakumar3243
    @lavakumar3243 ปีที่แล้ว +2

    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.

  • @atharvakalele37
    @atharvakalele37 2 ปีที่แล้ว +12

    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!

  • @jayantsingh2863
    @jayantsingh2863 6 วันที่ผ่านมา +1

    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?

  • @VivekJaviya
    @VivekJaviya 2 ปีที่แล้ว +169

    Leetcode daily problem + Codechef daily problem + GFG daily Problem + Striver Daily dp problem = :)

    • @sakthi6023
      @sakthi6023 2 ปีที่แล้ว +13

      =Google

    • @kingmaker9082
      @kingmaker9082 2 ปีที่แล้ว +8

      So, ur planning to become SDE in Meta 🤙

    • @VivekJaviya
      @VivekJaviya 2 ปีที่แล้ว

      @@kingmaker9082 Meta to nhi but USA ke startup or MNC se offer to mil gaye upar ki chijo se!

    • @kingmaker9082
      @kingmaker9082 2 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +3

      Are you saying practicing every day or are you talking about the problem which is given everyday on LeetCode and GfG?

  • @poisegaming2448
    @poisegaming2448 ปีที่แล้ว +1

    class Solution {
    public int climbStairs(int n) {
    int prev2 = 1;
    int prev1 = 1;
    for(int i =2;i

  • @lifehustlers164
    @lifehustlers164 8 หลายเดือนก่อน +4

    3/57 done!!! Understood!

  • @avakanksh
    @avakanksh 4 หลายเดือนก่อน +1

    UNDERSTOOD. But there is a small issue in the base case, n = 0 doesn't make any sense according to the problem, so we need to set the base case as n = 1 and n=2. Rest everything is understood. Thanks for the videos

  • @gurveer1527
    @gurveer1527 2 ปีที่แล้ว +5

    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

  • @rajneeshmishra6969
    @rajneeshmishra6969 2 หลายเดือนก่อน

    Understood! Loved how you simplified the recurrence relations thing!

  • @newtonsir6752
    @newtonsir6752 2 ปีที่แล้ว +6

    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 ปีที่แล้ว +1

      Bcoz there is only one way to reach step 1 from step 0

    • @vikasbagri1225
      @vikasbagri1225 2 ปีที่แล้ว +6

      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

  • @DeveshKumar-tj2rs
    @DeveshKumar-tj2rs 2 หลายเดือนก่อน

    UnderStood
    To create any recurrence relationship
    1. Treat the the question in the forM of indexing
    2. Do all possible things on the index
    3. Count or fine min of max to get your and.

  • @RAHULKUMAR-sx8ui
    @RAHULKUMAR-sx8ui 2 ปีที่แล้ว +5

    if logic is magic then you are a great magician appreciate it sir ❤️

  • @programmertik2046
    @programmertik2046 2 ปีที่แล้ว +2

    int ways(int i,int n, vector&dp){
    if(dp[i]!=-1){
    return dp[i];
    }
    if(i==n){
    return 1;
    }
    if(i>n){
    return 0;

    }



    return dp[i]=ways(i+1,n,dp)+ways(i+2,n,dp);
    }
    Why this gives heap buffer exceeded and why we go from n to 0
    when we go can go from 0 to n

  • @dharmeshpoladiya9047
    @dharmeshpoladiya9047 2 ปีที่แล้ว +5

    Understood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥

  • @insofcury
    @insofcury 2 ปีที่แล้ว +2

    Represent the problem in index format
    Do all possible operations on the index
    do count or find min/max
    Understood!

  • @lakshmichandhana
    @lakshmichandhana ปีที่แล้ว +4

    Amazing Lectures ,learnt a lot .Great initiative.

  • @ganapathyg981
    @ganapathyg981 2 ปีที่แล้ว +2

    Thanks for explaining in English.. love from Tamilnadu 😎

  • @nimsguy
    @nimsguy 2 ปีที่แล้ว +9

    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 ปีที่แล้ว +2

      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.

  • @codecrafts5263
    @codecrafts5263 6 หลายเดือนก่อน

    Tabulated solution:
    function f(n){
    if(n

  • @sakshisinghal1669
    @sakshisinghal1669 2 ปีที่แล้ว +7

    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 2 ปีที่แล้ว +12

      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 ปีที่แล้ว +1

      @@sandeepdeepu5052 thank u

    • @sandeepdeepu5052
      @sandeepdeepu5052 ปีที่แล้ว

      @@kaushikmahanta6463 felt happy that you understood my explanation.

  • @aryankumar87771
    @aryankumar87771 2 ปีที่แล้ว +2

    Python Most optimized solution =>
    def climbStairs(self, n: int) -> int:
    prev = 1
    prev2 = 1
    res = 1
    for x in range(2,n+1):
    res = prev + prev2
    prev2 = prev
    prev = res
    return res

  • @rashmikareddy3259
    @rashmikareddy3259 2 ปีที่แล้ว +3

    Learning to be consistent from you sir.. UNDERSTOOD

  • @sunildhiman90
    @sunildhiman90 ปีที่แล้ว +1

    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?

  • @atech_guide
    @atech_guide 2 ปีที่แล้ว +3

    Great Explaination in building the recursion. Thanks

  • @siddheshborse3536
    @siddheshborse3536 ปีที่แล้ว +1

    Not getting feeling of Solution....
    but understood the shortcut very well...
    thank you😀

  • @punitgarg4627
    @punitgarg4627 2 ปีที่แล้ว +8

    one small mistake ,for idx==1, return 1 aayega instead of 0, nicee explanation sir❤❤

    • @035asadali8
      @035asadali8 2 ปีที่แล้ว +4

      he mentioned in video ,u missed

  • @amalasebastian9968
    @amalasebastian9968 ปีที่แล้ว +1

    Liked the video even before starting it..Obviously its made by Striver ,it had to be great❤

  • @sakshiupadhyay3284
    @sakshiupadhyay3284 2 ปีที่แล้ว +3

    More power to you striver... "UNDERSTOOD"

  • @dhruvmehta957
    @dhruvmehta957 ปีที่แล้ว

    i just want to ask is this approach accurate
    int solve(int pos,int n, int sum){
    if(pos==n){
    return 1;
    }
    if(pos>n){
    return 0;
    }
    int left=solve(pos+1,n,sum);
    int right=solve(pos+2,n,sum);
    return left +right;
    }
    bcoz everyone is doing fib.. thing

  • @karanjitsinghrandhawa445
    @karanjitsinghrandhawa445 2 ปีที่แล้ว +4

    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 ❤️

  • @052_a_sourabhpathak5
    @052_a_sourabhpathak5 2 ปีที่แล้ว +1

    Damn , this is what tier 3 college should teach in DSA's classess!

  • @ketanahuja8939
    @ketanahuja8939 2 ปีที่แล้ว +5

    At 7:25 , it will be return 0 when (ind==0)

  • @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).

  • @devanshkumar3816
    @devanshkumar3816 2 ปีที่แล้ว +6

    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 ปีที่แล้ว +1

      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 2 ปีที่แล้ว +2

      @@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. :-(

  • @mohitagarwal1888
    @mohitagarwal1888 2 ปีที่แล้ว

    This is your only video till now that i didnt 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.

  • @amansinghal4663
    @amansinghal4663 ปีที่แล้ว +1

    when n==0, why did we return 1 ?
    we should have return 0 because there is no staircase present so 0 steps will be required to climb it.

  • @Sanya-ic8gr
    @Sanya-ic8gr 5 หลายเดือนก่อน +1

    UNDERSTOOD! Thank you striver!!

  • @ekta9145
    @ekta9145 4 หลายเดือนก่อน +1

    Understood! Thank you very much, sir.

  • @shaikkhizar8133
    @shaikkhizar8133 7 หลายเดือนก่อน +2

    Understood striver

  • @parthadhikari00
    @parthadhikari00 ปีที่แล้ว +1

    Should'nt the base case be " if(ind==0) return 0 ". Correct me if I'm wrong.

    • @lonerider6695
      @lonerider6695 8 หลายเดือนก่อน

      Same doubt if u got answer tell me

  • @yashrawat5158
    @yashrawat5158 ปีที่แล้ว +1

    //memoization
    #include
    #include
    using namespace std;
    int frog(int n,vector &dp){
    //base case explanation
    // If n is 0, the function returns 1. This is because if the frog is already at position 0, then it doesn't need to make any more jumps to reach position 0, so there is only 1 way to do so.
    //If n is 1, the function returns 1 as well. This is because if the frog is at position 1, it can only make one jump of 1 step to reach position 0, so there is only 1 way to do so.
    if(n==0){
    return 1;
    }
    if(n==1){
    return 1;
    }
    // condition for dp
    if(dp[n]==-1){
    int left=frog(n-1,dp);
    int right=frog(n-2,dp);
    return dp[n]=left + right;
    }
    else{
    return dp[n];
    }
    }
    int main(){
    int n;
    cin>>n;
    vector dp(n+1,-1);
    cout

    • @TheAI-Tutor
      @TheAI-Tutor 10 หลายเดือนก่อน

      bhai, if the frog is already at position 0, then it doesn't need to make any more jumps to reach position 0,
      SO IF oesn't need to make any more jumps to reach position 0, THEN WHY DOES HE NEED TO JUMP IF HE HAS ALREADY ARRIVED THERE? I'M V CONFUSED ABOUT THIS

  • @ashishabhinandanvlogs6083
    @ashishabhinandanvlogs6083 ปีที่แล้ว +1

    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 🔥🔥🔥

  • @ambharatrawat
    @ambharatrawat 2 ปีที่แล้ว +2

    Awsome explanation, memorize fibonacci solution in JS:
    const m = {};
    function fib(i) {
    if (i

  • @TarunKumarSaraswat
    @TarunKumarSaraswat หลายเดือนก่อน

    watching for 2nd time , makes more sense now

  • @DPCODE72
    @DPCODE72 2 ปีที่แล้ว +1

    Now I would believe in myself that I will be selected as A SDE in Amazon soon. Bhaiya with ur support & help.

  • @likhitbhogadi
    @likhitbhogadi 11 หลายเดือนก่อน +2

    thanks bro, understood..

  • @RituSharma-zp7xs
    @RituSharma-zp7xs ปีที่แล้ว +1

    isn't when index == 1, it should return 1 instead of 0.

  • @rushyya
    @rushyya ปีที่แล้ว

    Thanks for the Video!
    Understood
    2/56

  • @Lakshya-f4l
    @Lakshya-f4l 4 หลายเดือนก่อน

    Understood!
    Mark for revision!

  • @kathanvakharia
    @kathanvakharia ปีที่แล้ว

    Understood...Completed 2/56

  • @Lakshya-f4l
    @Lakshya-f4l 4 หลายเดือนก่อน

    Here's the c++ code which I submitted (For reference):
    int f(int n, vector &dp){
    if(n

  • @alicewarriors2028
    @alicewarriors2028 ปีที่แล้ว

    trust me striver. after watching your videos and solving many questions i am able to think how to solve any problem and only thing lagging behind that its not the complete solution
    my made up solutions always have some edge case which you always solve it

  • @somnathroy102
    @somnathroy102 ปีที่แล้ว

    This is so simple. Thank you Understood.

  • @easycode3189
    @easycode3189 2 ปีที่แล้ว +1

    nderstood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥

  • @ashb8552
    @ashb8552 ปีที่แล้ว

    #include
    using namespace std;
    int main() {
    int n=3;

    int prev2 = 1;
    int prev = 1;

    for(int i=2; i

  • @shivammishra2413
    @shivammishra2413 4 หลายเดือนก่อน

    understod.thanks striver bhaiya

  • @yashhokte1020
    @yashhokte1020 ปีที่แล้ว

    Striver one Lil confusion !! I understand the intuition behind taking n-1 and n-2 but I'm not able to understand why we were adding them ,like what's the intuition behind adding them ? Can you plz tell me?

    • @karanjotsinghbagga2097
      @karanjotsinghbagga2097 ปีที่แล้ว

      see think that f(n) as a recursive fn that will give soln to your recursionn problem . now how cann this func work ?? see you can either be taking two jumps or taking one jump . if you took a two jump means you were at f(n-2) and if you took a single jump means you were at f(n-1). now to reach the f(n) you coul have took a combination of one jump and two jumps . hence that f(n)=f(n-1)+f(n-2)

  • @rishabhgupta9846
    @rishabhgupta9846 ปีที่แล้ว

    can also solve using this way
    int helper(int i,int n,vector&dp){
    if(i==n)return 1;
    if(i>n)return 0;
    if(dp[i]!=-1)return dp[i];
    return dp[i]=helper(i+1,n,dp)+helper(i+2,n,dp);

    }
    int climbStairs(int n) {
    vectordp(n+1,-1);
    return helper(0,n,dp);
    }

  • @easycode3189
    @easycode3189 2 ปีที่แล้ว

    Understude Easily Nice Explanation

  • @replyplz8874
    @replyplz8874 2 ปีที่แล้ว +2

    Only question I had regarding ur explanation: when we try out all possibilities at particular index we can either go to i+1 or i+2. Why did we consider i-1 and i-2? Thanks for the overall explanation man!
    PS: I know we are looking from backwards. Can’t we do it by thinking this way?

    • @bharathkumar5870
      @bharathkumar5870 2 ปีที่แล้ว

      yes u can start with 0 and move to n

    • @bharathkumar5870
      @bharathkumar5870 2 ปีที่แล้ว +2

      //leetcode c++ solution
      //starting from step 0
      class Solution {
      public:
      int f(int i,int n,vector&dp){
      if(i==n-1)return(1);
      if(i==n-2)return(2);
      if(dp[i]!=-1)return(dp[i]);
      return(dp[i]=f(i+1,n,dp)+f(i+2,n,dp));
      }
      int climbStairs(int n) {
      vector dp(n+1,-1);

      return f(0,n,dp);
      }
      };

  • @vodnalasricharan1323
    @vodnalasricharan1323 2 ปีที่แล้ว +1

    Every Solution is giving TLE at codestudio. Only matrix multiplication solution is getting accepted

  • @OmkarShelke-w2j
    @OmkarShelke-w2j ปีที่แล้ว

    raj bhaiya "understood"

  • @UECAshutoshKumar
    @UECAshutoshKumar ปีที่แล้ว +1

    Thank you sir
    Understood

  • @Likithreddy...2310
    @Likithreddy...2310 2 หลายเดือนก่อน

    understood thanks for the resource

  • @stanleyalfred5076
    @stanleyalfred5076 ปีที่แล้ว

    So in tabultation method there is no need to fill array with -1 as we are not checking as in memoization format if iam not wrong

  • @roydebraj2188
    @roydebraj2188 4 หลายเดือนก่อน

    did it myself feels soo godd hehe

  • @anishsingh9043
    @anishsingh9043 ปีที่แล้ว +1

    I have a doubt, when we are on stair 0 and we have to calculate the no. of ways to reach stair 0 so why it is 1? Like we are already on the stair, so shouldnt it be 0 way. Because we have already reached there? Correct me please.

    • @catlord777x3
      @catlord777x3 5 หลายเดือนก่อน

      Bro let me help u,
      First understand we are callculating the no of way to reach each floor through recursion.
      Since 0 here denote the cur or ground floor and In order to reach ground or Current floor, how many option do we have,
      think about it.
      There is only 1 way, as u are already on ground floor.
      It can't be zero, as it would same as saying as ur on the ground or cur floor and u can't reach it, so trry understand the logic

  • @chetanthakral5322
    @chetanthakral5322 2 ปีที่แล้ว

    If index==1 , then the no. of ways should be 1 , because he can jump 1 step.

  • @Harshraj-xw4wb
    @Harshraj-xw4wb ปีที่แล้ว

    Understood the three points

  • @maheshgundlapalli4690
    @maheshgundlapalli4690 หลายเดือนก่อน

    thank you striver

  • @aagamjain2131
    @aagamjain2131 ปีที่แล้ว +1

    Awesome explanation!!
    Understood sir 🔥💯

  • @shivanshumishra0560
    @shivanshumishra0560 ปีที่แล้ว

    Understood !!! really awesome explaination........

  • @coder0799
    @coder0799 2 ปีที่แล้ว +1

    Now all CS student can do DP without any fear...

  • @AnitaSharma-bk4fc
    @AnitaSharma-bk4fc 4 หลายเดือนก่อน

    Understood thanks striver❤

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 3 หลายเดือนก่อน

    NICE SUPER EXCELLENT MOTIVATED

  • @vedantsharma2921
    @vedantsharma2921 2 ปีที่แล้ว

    how much time should i give to complete this playlist considering I have placements in 1 month?

  • @PRADHYUMNAP
    @PRADHYUMNAP 2 ปีที่แล้ว +2

    Is the pseudo code written wrong? Can any1 give insights on this? Striver wrote base codn saying if(index == 1) return 0; but it should have been something like if(index< 0) return 0;
    Because in input if we pass index value as 1 it will return 0 according to Striver's base cond but it should originally return 1 ryt?

  • @taiga2267
    @taiga2267 ปีที่แล้ว

    day 1:-climbing stairs,shortcut to recurrence relation formulae

  • @SwapnilChavan-im7xh
    @SwapnilChavan-im7xh ปีที่แล้ว

    Understood 🔥🔥🔥
    Thanks for Your teachings

  • @azad8000
    @azad8000 ปีที่แล้ว +1

    dp Solution :
    static int fun(int n, int [] dp){
    if(n==0){
    return 1;
    }
    if(n0){
    return dp[n];
    }

    int n1 = fun(n-1,dp);
    int n2 = fun(n-2,dp);
    int ans = n1+n2;
    dp[n]=ans;
    return ans;
    }

    • @maverick5056
      @maverick5056 ปีที่แล้ว

      It wont work for 1e18 test cases..

  • @chahakjain6787
    @chahakjain6787 2 ปีที่แล้ว

    very easy explanation sir!!

  • @sauravfarkade7032
    @sauravfarkade7032 ปีที่แล้ว

    Understood!!
    Points covered:
    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.

  • @priyatamkumar518
    @priyatamkumar518 2 ปีที่แล้ว

    understood , a lot of wishes for you