Hey there and welcome back.
So over here we have another interesting question which is called minimum cost climbing stairs.
So the question reads you are given an integer array cost where cost at index I is the cost of the ith
step on a staircase.
Once you pay the cost, you can either climb 1 or 2 steps.
You can either start from the step with index zero or the step with index one.
Return the minimum cost to reach the top of the floor, and it's given that the length of the cost array
will be definitely greater than or equal to two.
So this is an interesting question.
And we are also given an example.
So let's say the cost array which is given to us has three elements one, two and three.
So the indices over here are zero one and two.
So these are the three steps.
This is the step with index zero.
This is the step at index one.
And this is the step at index two.
And then this is the destination.
Notice that the destination is beyond the last index in the cost array.
And the expected output in this case is equal to two because we can start at this step over here.
Because in the question it's mentioned that we can either start from the step with index zero or the
step with index one.
So let's say we are starting over here.
That is at the step with index one.
And then we'll pay this amount which is two.
And we can use this step.
And we can either go one step or two steps.
But it's good to use two steps because that will ensure that we have reached the destination.
So that's why the total cost involved in this case would be two, because we're just using this step
over here.
So we will have to pay two and we will be able to reach the destination.
Now, what are a few other ways in which we could have reached the top or the destination?
We could have started at this step over here with index zero, and we could first take two steps and
then take one step.
So what would be the total cost involved in this case?
Because we are using this step.
And this step will have to pay the cost at these two indices which is one and three.
So the total cost would be one plus three which is equal to four.
Okay.
Now another way in which we could have reached the top could be by first taking one step from this step
and then taking two steps.
Okay.
So in this case we're using this step over here.
And we're using this step over here.
So we would have to pay one plus two which is a total of three.
So in this way, you can see there are multiple ways to reach the top.
And the question asks us to identify the path which would require the minimum amount to be paid.
And then we'll have to output that particular amount.
So this is the question at hand.
Now in the next video let's go ahead and see how we can solve this.