Hi, everyone, welcome to this new video.
So in our previous video, we discussed this recursive approach.
So in this video, what we will do, we will try to convert this recursive code to dynamic programming
code.
So let's just start writing the code before writing the code.
Let's define so what we'll do, we will create ADP's since there are N steps.
So we are going to create a deep array of and preferences and the last index will be in and out on will
be deep off.
And so what deep.
I represent DPF, I represent distinct ways to reach index.
I do reach a step, I write so DPF.
I represent the total number of distinct ways to each step I am going.
By this definition, our answer will be DPE often number of unique ways, number of different ways to
reach, step and write.
And we already have the best case, right.
So we have everything.
Let's just start writing the code.
So let's comment about this.
So we need to create a area of size in society and plus one.
Now, let's initialize the best case, so BP of zero will be when I'm standing at the ground level.
So similarly, if you want to reach step one, how many unique ways will be possible?
Only one, right?
By taking a step of one.
Now it's a trade.
And we know the reconciliation, so what is our answer?
I would answer was to reach step, i.e. you can reach from I mean, this one by taking a step of one
or you can reach from a minus to by taking a step of two, and that's it.
And finally, you are going to return your answer.
And our answer was B B of.
And so that will be the complete code.
Now let's discuss the variation for discussion, so in this case, what I'm doing is I am allowed to
take a step of one or take a step of either one or two.
Now, the question can be modified that you can take a step of one, two or three.
So in that case, what you will do, you will add head count steps and minus three.
Right.
Similarly, if the question is you can take a step of one, two, three and four, then you will also
add and minus four here.
And similarly, you will add the P of a minus three here, then DP of a minus four er plus and so on.
So similarly this value can be anything.
So in the question, if the question has been modified that given you need to reach the top basically
and step and you can take a jump of one, two, three, basically you can take a jump of that mix.
Right.
So in this question, the value of KS, basically two in the question, the value of KS to you can take
a jump of either one or two.
But now I'm modifying the question to a general approach.
So given that you can take a jump of gay means, you can take a jump off one, you can take a jump of
two, three, four.
OK, so I have modified the question.
So your problem is your homework is basically trying to modify this code so that this code works for
key and not just one and two.
Right.
So give it a try.
We will discuss the solution.
We will modify this code for General K in our next video so that other guys.
I will see you in the next one.
Thank you.