Hi, everyone, so this video is in the continuation of previous video, so we will discuss that in
this question.
You are given that you want to reach to the top that is in step and it is given that either you can
take a jump of one or you can take a jump of two.
But we have modified the question and the question is now you can take Jump-Off.
So in this question, the value of cage basically to so the value of K can be anything, for example,
then so the value of Gaist.
And that means you can take a jump of one, you can take a jump of two, three.
And so until then.
Right.
So let's see how we can modify this code to work for a General K, let's start writing the code, then
you will be able to understand.
So let's comment about this called.
So it is pretty obvious we need to create a debris size and plus one fine next step here to initialize
the base case.
So let's say we are initializing DEPI of zero to one.
If the value of any zero, how many number of B is out there?
There is only one.
We do not do anything.
Now, let's talk about this.
So one thing is pretty simple here, pretty straightforward here.
So here's the value of keyboards, too.
So that's why you write it two times.
If the value of K3, what you will do, you will add Deepthi minus three if the value of KS for you
will add plus DPF of a minus four.
Similarly, if the value of KS 10, then you will add DEPI of a minus five ie minus six, minus 10.
So what we need, we need a for loop here.
Right.
We need one for loop here to iterate or work.
Right.
And we are going to add all these values.
So after adding all these values DPF, I will be an addition of all these values.
So.
Right.
Pretty straightforward.
We need a for loop.
So first let I try to the debris so in equals one I elastin or close to when I placeless.
Our answer will be DEPI often as we have discussed this now we need a up rate and envelope.
We will add all the values.
So for adding the value let's say in answer.
So initially my answer is zero and we need a for loop to try to work.
So okay.
Let's name James Hardie.
Its J equals one J list and or close to K and the J plus plus answer plus equals to deep off i.e. minus
G.
And when you come out of this for loop your the payoff i.e. will be this answer.
So let me try to explain you what is happening here.
See if the value of K is two.
If the value of KS two then you can write i.e. minus one plus or minus two, DPL five, minus two.
Now if the value of KS basically let's say 100, then what can do.
You can write like this plus B of A minus three and so on until B of i.e. minus hundred.
Right.
You will do this.
So basically what is this.
This is simple for loop.
Right.
This is simple for loop to iterate over.
Okay, so I am migrating here.
So starting from one, starting from one talkee.
Wait till I am migrating and we are what we are doing, we are adding all these values.
So I am adding all these values.
I started from zero, I am adding all these values and then I am assigning all these values to Deepthi.
So I am assigning answer to the POV I write.
So we are doing exactly the same thing now in this case, in this problem statement, the value of K
is two.
So let's write to.
So it is given that the value of KS to.
So urgent care is to right now there is one problem in the school and what is the problem?
Problem is our court will encounter runtime error and wider and time error will happen.
So what I am doing, I am doing I my energy.
Right.
What if I my energy is less than zero?
Right, I mean, this can be less than zero, for example, if the value of AI is one and let's say
the value of just basically so one minus K in our case, it is two to one minus two.
It will become negative.
It will become less than zero.
So this value will become deep of negative something.
Right.
And that is basically not defined.
That is runtime error.
So we will only call this when I minus G is not zero, it is guerdon or close to zero G.
What is just basically jump.
Right, you can take a jump off when you can take a jump of two and the maximum, you can take a jump
off.
So let me also rename the Stooging.
So here, Jamie's jump.
Starting from jump one that makes them jump, that I can take is basically less than ago.
Stookey And the value of getting this question is two.
So this will be jump.
And as I explained, you will only you will only call this when I Minhas jump is positive.
That is greater than or equal to zero.
Then only you will be able to do this.
Otherwise your gold will give you a ring.
Temeraire right.
So I think I will call Wilberg.
Let's see.
OK, so identify.
OK, I need to right here jump.
Let's legitimate.
So our goal is working now, we have a general called, right?
So this will work for any Liedtke.
So now what we need to do.
So we forgot to discuss time, complexity for this problem.
So what was the time and the space complexity?
So we are creating a disparity of size and less.
So this is extremely big often.
And what is the time?
So we are just iterating over this area.
So time complexity is big off and in this case, what will be the time and the space complexity?
So space complexity, you are creating this area.
So again, the space complexity is big often because you are creating one day of sizing and what is
the time complexity.
So you are iterating and times and then each time you are creating daytimes.
So and in Tukey.
Right in this case, the value of case two.
So this will become and in total, which is nothing but big often.
Right.
But this is the general time and space complexity.
So this court will basically work for any given value of late, so we have generalized our.
So that is pretty much that.
I want to discuss this with video, guys.
So if you have any doubt, please do ask.
I will help you out.
So this is from this video.
I will see you in the next one.
Thank you.