Climbing Stairs (LeetCode 70) | Full solution with animations | Dynamic Easy | Study Algorithms

Поділитися
Вставка
  • Опубліковано 26 сер 2024

КОМЕНТАРІ • 183

  • @pcccmn
    @pcccmn 2 роки тому +47

    I have watched NeetCode, CS Dojo and Kevin Naughton's explanation but couldn't understand the concept behind arr[target] = arr[target-1] + arr[target-2] for this problem until I came across your "How to understand and attack" segment. Thank you for explaining like I'm 5.

    • @Arcadencebeats
      @Arcadencebeats Рік тому +2

      I had the same issue. He explained it so much better!

    • @edoreemmanuel4250
      @edoreemmanuel4250 9 місяців тому +1

      I am just seeing this..I love the explanation...lols....

    • @testing-js8iu
      @testing-js8iu 6 місяців тому +1

      yes you right

  • @user-dx4un7gg2z
    @user-dx4un7gg2z Місяць тому +4

    you simplified it to a level that my dumb brain can understand. Thank you.

  • @hiteshpaliwal8171
    @hiteshpaliwal8171 23 дні тому +1

    Your approach of explaining is far better than till I have see all videos. Thanks

  • @fourieruddin871
    @fourieruddin871 7 місяців тому +5

    Your excitement for teaching has no bounds 🙏

    • @nikoo28
      @nikoo28  6 місяців тому

      thanks for your kind words

  • @horcruxone
    @horcruxone 4 місяці тому +3

    Handsdown the best explanation available on youtube for leetcode 70!

  • @zb2747
    @zb2747 Рік тому +7

    Man great breakdown. I'm doing interview prep by grinding on leetcode and your videos have been a great way for me to understand how to solve set problems. You do a great job of talking slowly but not too slow and breaking the problem down that is simple to understand.

  • @vichitrakalakaar
    @vichitrakalakaar 2 роки тому +4

    I tried to solve this problem using recursion but TLE.... And you just gave me best solution .... Thank you so much guru🔥💯❤️🙏

  • @data10xwithsandeep
    @data10xwithsandeep 4 місяці тому +1

    Boss you are a king of coding and the best teacher

    • @nikoo28
      @nikoo28  4 місяці тому

      Thank you so much

  • @nerd6134
    @nerd6134 2 роки тому +15

    If this guy makes a math course it’ll be one of the best.

  • @1tav0
    @1tav0 2 роки тому +4

    I wish you could have been my teacher for dsa! You are a true teacher, this was so simple to follow I want to cry. Thank you so much sir! Please keep making this type of videos they are life savers for people like me! Thank you thank you! Please could you touch upon recursion and tree problems please !

    • @nikoo28
      @nikoo28  2 роки тому +2

      Thank you so much for your kind words. I do have videos on recursion and tree problems. Check out my playlist on algorithmic paradigms. :)
      I hope they are helpful too.

    • @santoshibora1892
      @santoshibora1892 Рік тому

      @@nikoo28 why array is of n+1 size, why cant n??

    • @krishkhemani96
      @krishkhemani96 7 місяців тому

      ​Bcz index starts at 0 if you want to calculate the 8 step you need ans of 8th index but if u pick array of size n you would be providing ans of 7th index instead of 8​@@santoshibora1892

    • @erickjhormanromero6905
      @erickjhormanromero6905 3 дні тому

      @@santoshibora1892 because you need to store all the number of ways for each position of n, that's for memo in that case example dp[0,1,2,3,5,8,13] so if you need to get the max of the steps for n = 13 you go to the dp and return that exactly value.

  • @Ranjan-xc5nl
    @Ranjan-xc5nl 2 місяці тому

    Provides sound explanation of algorithmic approach and solution, indeed worthy channel. Thanks.

  • @leonardocavalcanti1225
    @leonardocavalcanti1225 16 днів тому +1

    Excellent explanation!
    BTW, the solution of this problem is the Fibonacci sequence.

  • @Mr.Zeus11
    @Mr.Zeus11 4 місяці тому

    Thank you so much, first time while I saw the problem, i was like WTH how I am gonna solve this. After seeing your video it's so easy!! ❣

    • @nikoo28
      @nikoo28  4 місяці тому

      Love it!!! 😁

  • @savitrik3596
    @savitrik3596 Місяць тому

    i find it much easier to understand these dsa problems when they are reduced to some math equivalent like at 11:49 Thank you so much

  • @kavinsanthosh1306
    @kavinsanthosh1306 Рік тому +1

    Great explanation! This is my first DP, Memoisation Problem!

    • @nikoo28
      @nikoo28  Рік тому

      you are gonna love dynamic programming. Check out House Robber as well. ua-cam.com/video/VXqUQYGMnQg/v-deo.html

  • @ajaygunalan1995
    @ajaygunalan1995 Рік тому +2

    Dude, you nailed it. LOVE YOU!

    • @nikoo28
      @nikoo28  Рік тому +1

      Glad you enjoyed it 😄

  • @niktri6805
    @niktri6805 2 місяці тому

    Really excellent explanation, the breakdown of the problem made it much more easier to understand.

  • @sa35085nhs
    @sa35085nhs 7 місяців тому +1

    I read one of comment which was recently posted, but u replied to that comment also,great !!!

  • @dirtbag1126
    @dirtbag1126 Рік тому +1

    Great video! Loved the visuals. You did an excellent job at breaking down the steps needed to approach this problem. Keep it up!

    • @nikoo28
      @nikoo28  11 місяців тому

      glad you liked it. If you want to see more content like this, consider joining my channel: ua-cam.com/channels/T-S2ngqEBoYCM5UKuNeELg.htmljoin

  • @kuoyulu6714
    @kuoyulu6714 Рік тому

    just starting my leetCode journey, with no math background, this video helped me so much, thanks a lot!

    • @nikoo28
      @nikoo28  Рік тому +1

      I wish you all the very best :)

    • @kuoyulu6714
      @kuoyulu6714 Рік тому

      @@nikoo28 thanks!

  • @jamjam3448
    @jamjam3448 4 місяці тому

    Wowww. Thanks a million bro. After watching many turotials on this, yours is the best! I've understood it! Thanks

  • @srikarjonnala6509
    @srikarjonnala6509 2 місяці тому +1

    such a lovely solution and explanation

  • @NiteshMaurya1111
    @NiteshMaurya1111 Місяць тому

    wow I learn now what is dp and memorization thank you sir

  • @kunalchauhan5294
    @kunalchauhan5294 7 місяців тому +1

    Thank you soo much this is my 1st dp question I'm glad i found good description of it thank a lot you are a great tutor

  • @oluwatosinoseni5413
    @oluwatosinoseni5413 19 днів тому

    This is amazing! Thank you

  • @yousefnegmeldin5903
    @yousefnegmeldin5903 3 місяці тому

    Thank you so much, you helped me understand dynamic programming with such a simple explanation and example.

  • @arjunb9342
    @arjunb9342 Рік тому +1

    Thank you so much... Best and Easiest explanation ever .

  • @tiyashasen5020
    @tiyashasen5020 Рік тому +1

    You teach amazing. Thanks for making us understand difficult concepts in a simple way🙂

    • @nikoo28
      @nikoo28  Рік тому

      Glad you feel this way :)

  • @shortme9374
    @shortme9374 4 місяці тому

    Hey Nikhil, I really liked your way of explanation. keep making such videos. Subscribed.

    • @nikoo28
      @nikoo28  4 місяці тому

      Thanks for the sub!

  • @XYZ-od7zg
    @XYZ-od7zg 17 днів тому +1

    Great video

  • @MrMichalXXL
    @MrMichalXXL 9 місяців тому

    I was skeptical but in the end you delivered the understanding

    • @nikoo28
      @nikoo28  8 місяців тому

      glad i could help you

  • @ram_mandir_india
    @ram_mandir_india 9 місяців тому

    The way you explained it made it so easy to understand. Thank you, my friend, for helping me in my first dynamic programming question. Love from Haryana.

    • @nikoo28
      @nikoo28  8 місяців тому

      You're very welcome!

  • @priyagupta5139
    @priyagupta5139 3 місяці тому

    Your Explanation is very good.

    • @nikoo28
      @nikoo28  3 місяці тому

      Glad you think so!

  • @shiva3499
    @shiva3499 20 днів тому

    Wow, Thanks Man It's Very Useful Content Once Again Thank You Pls Be Going....

  • @ayaanrashid960
    @ayaanrashid960 26 днів тому

    awesome explaination bhaiya

  • @saikiran1426
    @saikiran1426 2 дні тому

    Nice explanation 😊

  • @RakshithVrishab-ht8vk
    @RakshithVrishab-ht8vk 9 місяців тому

    The best explanation i have come across, i have watched other videos of same problem from other instructors , their explanation was also good, but Nikhil the way you've explained is so simple and top notch, thank you very much

    • @nikoo28
      @nikoo28  9 місяців тому

      really glad you feel that way 😄

  • @sreeharsharaveendra289
    @sreeharsharaveendra289 8 місяців тому

    Best explanation behind the thought process of approaching the problem. I think we can reduce the space complexity to O(1) because we just need to return the value for the number of ways to reach the nth step. So a sliding window approach can also work, which is kinda similar to dynamic programming, but you don't memoize all values, just the previous 2 values and keep updating it.

    • @nikoo28
      @nikoo28  7 місяців тому +1

      Excellent

  • @dailyprograming9003
    @dailyprograming9003 11 місяців тому

    your explanation skill is too good

  • @susmitobhattacharyya1668
    @susmitobhattacharyya1668 9 місяців тому +1

    Thanks for your simple explanation.

  • @vasavi5908
    @vasavi5908 11 місяців тому +1

    Great explanation.Thank you very much

  • @feedingdotnet8904
    @feedingdotnet8904 22 дні тому

    Awesome..explanation

  • @purnachandrasahu622
    @purnachandrasahu622 7 місяців тому +1

    This was really helpful!!
    Keep up the good work..

  • @ParmodYadav
    @ParmodYadav 7 місяців тому

    Very good way to teach brother very depth understanding of the question very good

  • @dhatrikaakepati9623
    @dhatrikaakepati9623 19 днів тому

    Thank you 😇

  • @DeveloperJay
    @DeveloperJay 6 місяців тому

    the way of explaining was very very good. but we can use simple Fibonacci approach as well.

    • @nikoo28
      @nikoo28  5 місяців тому

      but how would you know that it is a fibonacci sequence??

  • @TaufeeqAhmed-hk4rz
    @TaufeeqAhmed-hk4rz 6 місяців тому

    Awesome Explanation bro

    • @nikoo28
      @nikoo28  6 місяців тому

      Thank you so much 🙂

  • @abhishekkeshri3974
    @abhishekkeshri3974 Рік тому

    you make me fall in love with dynamic programming .please do a live talk with us and give some advices for interview . thanks for the video nikhil.

    • @nikoo28
      @nikoo28  Рік тому +1

      glad you liked the video. Check out my latest video on Edit Distance too. Just uploaded it today :)
      I will have a youtube live coming up soon.

    • @abhishekkeshri3974
      @abhishekkeshri3974 Рік тому

      @@nikoo28 glad to know. We like to talk with you.

  • @sukanyaghosh24
    @sukanyaghosh24 10 місяців тому

    Omg such an amazing explanation, thank you so much sir 🙏❤️

  • @prashanthshetty8337
    @prashanthshetty8337 5 місяців тому

    This can be done using 2 ints as well.
    ```golang
    func climbStairs(n int) int {
    if (n == 1 || n == 2) {
    return n
    }
    a, b := 1, 1
    for i := 2; i < n; i++ {
    a, b = b, b + a
    }
    return a + b
    }
    ```

  • @user-wg6nk7ix7x
    @user-wg6nk7ix7x 8 місяців тому +2

    Man great breakdown of this problem, simply the best!

  • @AkashYadav-di6kd
    @AkashYadav-di6kd 7 місяців тому +1

    Thank you very much, sir.

  • @nikhilmishra8266
    @nikhilmishra8266 7 місяців тому

    observing the output we can also use simple fib program

  • @yashthakur5712
    @yashthakur5712 7 місяців тому

    hats off to you sir, excellent explanation, and thnks a lot

  • @omkarkhandalkar8869
    @omkarkhandalkar8869 2 роки тому

    Really helpfull sir
    The way you're explaining is >>>>>>>>>>>>>>>>>>>>>>>>> any other course or youtube channel

    • @nikoo28
      @nikoo28  2 роки тому

      It will be so helpful if you tell about my channel to your friends/colleagues as well 😃

    • @omkarkhandalkar8869
      @omkarkhandalkar8869 2 роки тому

      @@nikoo28 yes sir shared with community groups

  • @ashok2089
    @ashok2089 22 дні тому

    amazing!

  • @Deepz007
    @Deepz007 4 місяці тому +1

    Yours was the best explanation.

  • @vsh-torch
    @vsh-torch 2 роки тому +1

    Good one, bro. Thank you.

  • @kasifmansuri7552
    @kasifmansuri7552 Рік тому +1

    Great explaination!!

  • @unemployedcse3514
    @unemployedcse3514 21 день тому

    actually I left this problem since it was DP , now I will attack this problem ❤😂

    • @nikoo28
      @nikoo28  21 день тому

      you are gonna love the solution 😄

  • @SHAIKAFTABAHMED-gz9wu
    @SHAIKAFTABAHMED-gz9wu Місяць тому

    Bro u r really a bro ....

  • @shivashankar6043
    @shivashankar6043 9 місяців тому +2

    So, its a modified question of finonacci series problem

    • @nikoo28
      @nikoo28  9 місяців тому

      not exactly...it just happens to have a fibonacci pattern.

  • @ritendahiya8828
    @ritendahiya8828 7 місяців тому +1

    Thank you sir!!

  • @latest_news_stories
    @latest_news_stories Рік тому +1

    Lit 🔥very well explained

    • @nikoo28
      @nikoo28  Рік тому

      You too are awesome 😎

  • @adnaan28
    @adnaan28 4 місяці тому

    just an amazing explanation

    • @nikoo28
      @nikoo28  2 місяці тому

      Glad you think so!

  • @rubylnic
    @rubylnic Рік тому

    thank you for the great explanation!

  • @moshemaor1731
    @moshemaor1731 24 дні тому

    Nice and clear explanation. Is it possible I have invented something? The numbers you have written in the boxes: 1 2 3 5 8 13 21 34 .. Are the fibonnacci sequence..

  • @gauravkumar-ek8mr
    @gauravkumar-ek8mr 2 роки тому

    Adbhoot. Love your explanation

  • @_Adil.Khan_
    @_Adil.Khan_ 2 роки тому +1

    I will say just fantastic!

  • @abhishekkr8077
    @abhishekkr8077 Рік тому

    Bahut badhiya padhate ho sir aap 🙏

    • @nikoo28
      @nikoo28  Рік тому

      thank you so so much

  • @Rajendrachoudhary-ut8ll
    @Rajendrachoudhary-ut8ll 4 місяці тому

    Awesome explanation

  • @skrishnan9625
    @skrishnan9625 6 місяців тому +1

    This problem can also be done with the help of recursion

  • @codeflix927
    @codeflix927 Рік тому

    it's Amazing explanation . I loved it.❤❤❤❤❤❤❤❤❤❤❤❤

  • @mohitarya5189
    @mohitarya5189 Рік тому +1

    Thank you 😊😊

  • @user-dr4yj6dd7q
    @user-dr4yj6dd7q 10 днів тому

    You are simply super nikhil👌🏻, I have few doubts is there any platform where I could connect with you

    • @nikoo28
      @nikoo28  10 днів тому

      you can email me

  • @user-qy2fm3pu2b
    @user-qy2fm3pu2b Місяць тому

    great man...!!!!

  • @Muhammed___koya
    @Muhammed___koya 2 місяці тому

    but if the no of stairs is 1 your code will cause indexoutofboundexception. In order to avoid that you should initialize 0 index value and 1 index value to 1 and run the loop starting from i=2;

  • @sammedpatil3907
    @sammedpatil3907 2 роки тому

    very nice method of explanation....

  • @apuravsharma9995
    @apuravsharma9995 9 місяців тому

    Great explanation

  • @minecraftredstoneinspiration

    Really well explained.

  • @hommy4850
    @hommy4850 Рік тому

    well explained thanks you!!

  • @kanimozhikani7138
    @kanimozhikani7138 10 місяців тому

    Thank you so much sir🎉

  • @rinkishaw1929
    @rinkishaw1929 4 місяці тому

    Great video ❤

  • @Arcadencebeats
    @Arcadencebeats Рік тому

    Thank you so much!

  • @jritzeku
    @jritzeku 8 місяців тому

    Is it bad to use recursive solutions for dynamic programming? I simply used recursion similar to fibonacci and then to make it more performant used a memo obj. That way it will avoid recursion for already encountered inputs. The tabulation approach seems lot less intuitive for more complex problems.

    • @nikoo28
      @nikoo28  7 місяців тому +1

      I won't say bad to use recursion but it is definitely less intuitive. When something goes wrong it is very hard to trace what happened, and fixing it becomes problematic. Recursive solutions look small for sure, but it is not necessary that they take less space as well.

  • @machans-203
    @machans-203 4 місяці тому

    You can reduce space complexity to O(1). It's a fibonnaci series in other name👍

    • @nikoo28
      @nikoo28  4 місяці тому

      But you need to understand the problem before you can derive the fibonacci series

  • @kunalkheeva
    @kunalkheeva Рік тому

    great content!

  • @TrueRDX
    @TrueRDX Рік тому

    thanks very much for explain dp 🤗

    • @nikoo28
      @nikoo28  Рік тому

      Thank you so much 😊

  • @carlosraul6578
    @carlosraul6578 Рік тому

    Thanks my bro

  • @rishabhsinghal5823
    @rishabhsinghal5823 Рік тому

    very nice explanantion baat to hai..

  • @sathiroy4788
    @sathiroy4788 Рік тому

    Nice explanation.

  • @agentphoenixtm642
    @agentphoenixtm642 Рік тому

    Isnt this is tabulation rather than memoization? As we following bottom up approach from base case to final result 13:37

    • @nikoo28
      @nikoo28  11 місяців тому

      by tabulation if you mean storing all results in a table, then yes it is the same. Memoization is just a concept to store your calculated results, you do it in any data structure you like as long as you are saving space/time.

  • @ujjawaltyagi3095
    @ujjawaltyagi3095 6 місяців тому

    why +1 i didn't get it ? isn't it like prefix sum? so we are basically storing sum of last two ele so why we need n+1 size instead of n ?

    • @nikoo28
      @nikoo28  5 місяців тому

      that is just to avoid index out of bounds exception

  • @filmbuzz9419
    @filmbuzz9419 10 місяців тому

    Min Cost Climbing Stairs also make vedio on these quation

    • @nikoo28
      @nikoo28  10 місяців тому +1

      let me find it

  • @rajnishroy7429
    @rajnishroy7429 Рік тому

    thank u..

  • @sukanyaghosh24
    @sukanyaghosh24 10 місяців тому

    Sir please make a series of all the 150 neet code questions using java, it's a humble request 🥺

    • @nikoo28
      @nikoo28  10 місяців тому +1

      Will upload soon

    • @sukanyaghosh24
      @sukanyaghosh24 10 місяців тому

      @@nikoo28 thank you ☺️

  • @omarkhan5223
    @omarkhan5223 Рік тому

    Great video, what tool are you using with your pen to make those bright red lines?

    • @nikoo28
      @nikoo28  Рік тому

      that is an application called GoodNotes 6

  • @astra8072
    @astra8072 Рік тому

    so solution of this problem is basically a fibbonacci?

    • @nikoo28
      @nikoo28  11 місяців тому

      you are absolutely correct. Watch another fun video on fibonacci series: ua-cam.com/video/WuMTCaM2pk8/v-deo.html

  • @Kemba_oak
    @Kemba_oak 3 місяці тому

    this feels exactly like Fibonacci sequence

    • @nikoo28
      @nikoo28  3 місяці тому

      Yes, but you need to arrive at that conclusion first

  • @ScienceAndTech-Core
    @ScienceAndTech-Core 7 місяців тому

    I understood how to implement the code and I used recursion, like this:-
    public class Solution{
    public int climbStairs(int n) {
    return fib(n);
    }
    public int fib(int n){
    if(n

    • @brunosdm
      @brunosdm 7 місяців тому

      That will have a LOT of redundant method calls, but you can keep the recursive approach if you use memoization. Look that up.
      There's also videos explaining this solution with that approach.

    • @ScienceAndTech-Core
      @ScienceAndTech-Core 7 місяців тому

      @@brunosdm Oh! I looked up memoization and watched the explanation by hackerrank. Thanks!

    • @nikoo28
      @nikoo28  6 місяців тому

      absolutely correct, with memoization you can store your results..so you are not computing again and again.