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.
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.
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 !
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.
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
@@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.
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.
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
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.
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 } ```
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..
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;
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.
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.
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.
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
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.
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.
I had the same issue. He explained it so much better!
I am just seeing this..I love the explanation...lols....
yes you right
you simplified it to a level that my dumb brain can understand. Thank you.
Your approach of explaining is far better than till I have see all videos. Thanks
Your excitement for teaching has no bounds 🙏
thanks for your kind words
Handsdown the best explanation available on youtube for leetcode 70!
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.
same here
I tried to solve this problem using recursion but TLE.... And you just gave me best solution .... Thank you so much guru🔥💯❤️🙏
Boss you are a king of coding and the best teacher
Thank you so much
If this guy makes a math course it’ll be one of the best.
true..and everyone will start coding.
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 !
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.
@@nikoo28 why array is of n+1 size, why cant n??
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
@@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.
Provides sound explanation of algorithmic approach and solution, indeed worthy channel. Thanks.
Excellent explanation!
BTW, the solution of this problem is the Fibonacci sequence.
Yeah
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!! ❣
Love it!!! 😁
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
Great explanation! This is my first DP, Memoisation Problem!
you are gonna love dynamic programming. Check out House Robber as well. ua-cam.com/video/VXqUQYGMnQg/v-deo.html
Dude, you nailed it. LOVE YOU!
Glad you enjoyed it 😄
Really excellent explanation, the breakdown of the problem made it much more easier to understand.
I read one of comment which was recently posted, but u replied to that comment also,great !!!
Great video! Loved the visuals. You did an excellent job at breaking down the steps needed to approach this problem. Keep it up!
glad you liked it. If you want to see more content like this, consider joining my channel: ua-cam.com/channels/T-S2ngqEBoYCM5UKuNeELg.htmljoin
just starting my leetCode journey, with no math background, this video helped me so much, thanks a lot!
I wish you all the very best :)
@@nikoo28 thanks!
Wowww. Thanks a million bro. After watching many turotials on this, yours is the best! I've understood it! Thanks
such a lovely solution and explanation
wow I learn now what is dp and memorization thank you sir
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
This is amazing! Thank you
Thank you so much, you helped me understand dynamic programming with such a simple explanation and example.
Thank you so much... Best and Easiest explanation ever .
You teach amazing. Thanks for making us understand difficult concepts in a simple way🙂
Glad you feel this way :)
Hey Nikhil, I really liked your way of explanation. keep making such videos. Subscribed.
Thanks for the sub!
Great video
I was skeptical but in the end you delivered the understanding
glad i could help you
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.
You're very welcome!
Your Explanation is very good.
Glad you think so!
Wow, Thanks Man It's Very Useful Content Once Again Thank You Pls Be Going....
awesome explaination bhaiya
Nice explanation 😊
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
really glad you feel that way 😄
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.
Excellent
your explanation skill is too good
Thanks for your simple explanation.
Great explanation.Thank you very much
Awesome..explanation
This was really helpful!!
Keep up the good work..
Very good way to teach brother very depth understanding of the question very good
Thank you 😇
the way of explaining was very very good. but we can use simple Fibonacci approach as well.
but how would you know that it is a fibonacci sequence??
Awesome Explanation bro
Thank you so much 🙂
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.
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.
@@nikoo28 glad to know. We like to talk with you.
Omg such an amazing explanation, thank you so much sir 🙏❤️
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
}
```
Man great breakdown of this problem, simply the best!
Thank you very much, sir.
observing the output we can also use simple fib program
hats off to you sir, excellent explanation, and thnks a lot
Really helpfull sir
The way you're explaining is >>>>>>>>>>>>>>>>>>>>>>>>> any other course or youtube channel
It will be so helpful if you tell about my channel to your friends/colleagues as well 😃
@@nikoo28 yes sir shared with community groups
amazing!
Yours was the best explanation.
Good one, bro. Thank you.
Great explaination!!
actually I left this problem since it was DP , now I will attack this problem ❤😂
you are gonna love the solution 😄
Bro u r really a bro ....
So, its a modified question of finonacci series problem
not exactly...it just happens to have a fibonacci pattern.
Thank you sir!!
Lit 🔥very well explained
You too are awesome 😎
just an amazing explanation
Glad you think so!
thank you for the great explanation!
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..
Adbhoot. Love your explanation
I will say just fantastic!
Bahut badhiya padhate ho sir aap 🙏
thank you so so much
Awesome explanation
This problem can also be done with the help of recursion
it's Amazing explanation . I loved it.❤❤❤❤❤❤❤❤❤❤❤❤
Thank you 😊😊
You are simply super nikhil👌🏻, I have few doubts is there any platform where I could connect with you
you can email me
great man...!!!!
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;
very nice method of explanation....
Great explanation
Really well explained.
well explained thanks you!!
Thank you so much sir🎉
Great video ❤
Thank you so much!
You're welcome!
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.
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.
You can reduce space complexity to O(1). It's a fibonnaci series in other name👍
But you need to understand the problem before you can derive the fibonacci series
great content!
thanks very much for explain dp 🤗
Thank you so much 😊
Thanks my bro
very nice explanantion baat to hai..
Nice explanation.
Keep watching
Isnt this is tabulation rather than memoization? As we following bottom up approach from base case to final result 13:37
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.
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 ?
that is just to avoid index out of bounds exception
Min Cost Climbing Stairs also make vedio on these quation
let me find it
thank u..
Sir please make a series of all the 150 neet code questions using java, it's a humble request 🥺
Will upload soon
@@nikoo28 thank you ☺️
Great video, what tool are you using with your pen to make those bright red lines?
that is an application called GoodNotes 6
so solution of this problem is basically a fibbonacci?
you are absolutely correct. Watch another fun video on fibonacci series: ua-cam.com/video/WuMTCaM2pk8/v-deo.html
this feels exactly like Fibonacci sequence
Yes, but you need to arrive at that conclusion first
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
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.
@@brunosdm Oh! I looked up memoization and watched the explanation by hackerrank. Thanks!
absolutely correct, with memoization you can store your results..so you are not computing again and again.