Hi, everyone.
So in this video, also, we are discussing the question of minimum steps to one, but in this video
we will implement the bottom of the creative solution.
So in the last video, what we did, we created an Eddie.
The name of that, it was on set and the size of that it was and Blessin and I initialised David minus
one initially.
Then I told you my answer was this one, so this is the last index my -- will represented.
Now what will happen for calculating?
And so just like Fibonacci, for calculating and what it will do?
So in the worst case, there will be three calls.
So it will call on and minus one it will call on.
And by two, it will also call an end by three.
Similarly again, what will happen?
So for calculating and minus one, it will again call on and minus two.
So again, half.
And then again one third.
So this will go on.
And finally, what will happen?
So we will hit the Biscuit's.
So 011 they are the best case.
They both are containing zeros.
So finally I will reach here and then I will fill this position.
Then next position will be filled.
Then the next position will be filled, the next position will be filled.
Then this position will be filled.
And then finally this position will be filled.
And we will then I would answer.
So again, just like in Fibonacci, what we are doing, we are first reversing in this direction, then
we are filling the area while we are moving in this direction.
So what we can do, we can avoid moving in this direction.
We can directly move in this direction and can fill that.
OK, so what we will do, we will create again.
So for Bottom-Up DEPI, again, we have to create our area.
So what I will do, I will create an area.
So let's say this time I'm naming the area, Deepti.
OK.
So again, the size will be in plus one.
So what we have to do since we are, we will fill that in this direction.
I will initialize my 021 index.
So if you are standing at one M. steps required at zero and four zero zero zero.
So this is the net position.
OK, so what we will do, this is the eighth position.
So what is BP, what does Deepthi contains?
So this is BP office or BP a I mean, minimum steps required to move from eye to one.
So this is the meaning of BP of a minimum steps required to move from position to position.
So what is deep and so deep and contains the steps required from moving the position and to one?
What will my answer?
My answer will be BP often.
So this will be my answer.
So I'm repeating myself, despite the meaning of the fire, is basically minimum steps required to move
from to one.
So that means DPF and next steps required to move from nine to one.
And that is my answer.
OK, so this position will be my answer.
Now what is Deepthi?
How can we flip your face or typify what it will do?
So there are three options available, so I will take the minimum of three options.
So first one is deep of i.e. minus one.
The second option is deep of I bitou and also we will check if I am or two is zero and the third is
basically deep off.
I buy three again.
We have to check.
So we will take the minimum of these three and I will add plus one.
Simple.
So you want to calculate Deepthi what you will do.
Golon Deepthi minus one.
Collen, deep of battle and colon deep, DPF so deep I buy three, take the minimum of these three and
obviously since you took one jump to reach there.
So that's why you will add plus one.
OK, so very, very simple.
So now let us implement the bottom of DP.
So let's say that there will always be a..
Obviously, it will be easier, so the name of the function is minimum steps three it will take and
as input now what we have to do.
So I have to create an idea first, so instead, let's name BP, because at many places you will see
the name of that is DPE.
OK, so many people use Dippin, so let's name their DP.
And the size of the is basically and plus one.
Now, what they have to do, so you have to initialize the base case, so here.
So basically, so what will do will initialised the 010 first position, so DPF zero is zero and DEPI.
Often is one.
So what does 80 percent.
So I'm reading it here so that you can understand sort of I present the minimum steps.
Needed.
To move.
To move from I to one, so that means going by this definition.
So that means my answer should be DEPI often simple.
OK, so now we have to fill this out.
So now let us fill this area.
So I will start feeling from two because 091 these indexes have already been filled and obviously I
have to go in and I placeless, then what will do?
So again, we have to copy this code.
We will do very similar to copy this code.
So, Pastor Ted, now, what are the changes that we have to do?
So obviously, we need expert.
We do not have to call any function.
All right, so is basically the first option, five minus one, Y and Z, Y and Z will be initialized
with in the maximum.
Then what we have to do so.
I have to check, so if I go back to what is way, so why is nothing, it is just a of faith and by
doing so this is DBF and BITOU.
And similarly, I will check for a.
So if I is little bit, then it will be deep of inventory.
Sort of arbitrary, not an.
OK, so we are constructing a very.
This is the best case then, despite the definition, is Muno steps required to move from to so going
by definition, Dancer will be present at DEPI often.
So now I am feeling the are starting from tootle in shapelessness, so first option X, Y, minus one
Y and Z Visored and A more to zero, five by five by three.
And finally, what you can do, you can return your answer, which is DPF and.
Simple.
So now let's call this function.
So out.
Minimum steps three, and we will pass an.
And OK, so I think we did everything fine, so let's test our on.
OK, so this is minimum steps three.
Now, let's say the value of N is, let's say 250.
OK, so we did something we did something wrong.
Let me check.
So this will be zero.
This individual, because if you are standing at one, then if you want to reach one, so the value
will be zero.
OK.
Minimum steps required will be zero.
So here we did zero, but here, I don't know how, but I write one.
So sorry for that.
So let's say 9:00 to 5:00.
Again, zero strange.
OK, so very huge mistake.
So here what we are doing, we have to take a minimum and we have to add plus one.
So I'm not doing this.
So this is deep of a.
What you have to do, we have to take so if you will see.
So Depfa is actually we have to take the minimum minimum of these three and we have to add plus one,
so I forgot to write this one.
OK, I'm so sorry.
Today's my bad luck, I think so I have to take a minimum of X, then again, minimum of Y and Z and
plus one.
Now, this time, Richard, voxel 95.
Yes, so this is working, OK, our output is coming out.
OK, great.
So let's test it one more time.
Now, let's say the value is.
265, so, yes, it is working, OK, so our goal is working.
Now, what is the time, complexity of this cold?
So basically will see carefully what we are doing, we are just creating an area and we are simply activating.
So the time complexity is big often and also the space complexity is big often because we are constructing
this area.
Now, one more thing, since I have used a dynamic location, so what we can do so before returning
the answer, you can store the answer in a variable and then believe that and then return the answer.
OK, so you have to delete the memory yourself.
OK, so I forgot to delete and you can only tell yourself now one more thing.
So if you are tired of writing X, Y, Z, so what you can do.
So let me copy, let me comment on this called.
So there's no need to create X, Y and Z variables, which you can do.
The logic is the same, but the way of writing is different.
So what will do?
So I will write initially DPE of.
I is actually DPF, I mean, this one, then here I will write the BofI.
Is minimum of.
The current value of a.
And if I were to.
And again, deep of I.
Is minimum of Deepthi.
And fire Batory.
So this will be plus one.
Again, DPL five by two plus one, five, three plus one, and then you can remove this line.
OK, so the logic is the same, everything the same, but the way of writing the code is different.
So initially I am initializing BofI with DPL five minus one, plus one, and then I'm taking a minimum
here.
If I little by two, then I'm taking the minimum of the current value that I have and I buy two plus
one.
And similarly, if I resolve it, then DPO five will be minimum of the current value of deeper and deeper
if by three plus one.
OK, so I have commented out this one old one and let's test this one also.
The value is, let's say 85 and yes, our gold is working, so if you prefer this one approach X, Y,
Z, you can use this one and if you can preffered this one approach so you can use this one.
Both are correct and what you have to do here so you can do it yourself.
So first you have to delete the idea that we have a look at it.
OK, so delete the array.
So let me do it for you.
OK.
So what you have to do, so first you will store your answer because you have to delete the.
So let's take a variable answer, so the answer is deep in.
Then you will do that, so delete keyword.
The name of that is BP, and then you will return the answer.
OK, so let's test.
Well.
So three, OK, so our court is looking.
So if you have any doubt in these questions, you can ask me, I will see you in the next one by.