1
00:00:00,110 --> 00:00:01,850
Hey there and welcome back.

2
00:00:01,850 --> 00:00:08,000
So over here we have another interesting question which is called minimum cost climbing stairs.

3
00:00:08,000 --> 00:00:16,640
So the question reads you are given an integer array cost where cost at index I is the cost of the ith

4
00:00:16,640 --> 00:00:18,440
step on a staircase.

5
00:00:18,830 --> 00:00:23,660
Once you pay the cost, you can either climb 1 or 2 steps.

6
00:00:24,320 --> 00:00:29,840
You can either start from the step with index zero or the step with index one.

7
00:00:29,840 --> 00:00:36,800
Return the minimum cost to reach the top of the floor, and it's given that the length of the cost array

8
00:00:36,800 --> 00:00:39,740
will be definitely greater than or equal to two.

9
00:00:39,770 --> 00:00:41,570
So this is an interesting question.

10
00:00:41,570 --> 00:00:43,760
And we are also given an example.

11
00:00:43,760 --> 00:00:49,610
So let's say the cost array which is given to us has three elements one, two and three.

12
00:00:49,610 --> 00:00:52,430
So the indices over here are zero one and two.

13
00:00:52,460 --> 00:00:54,290
So these are the three steps.

14
00:00:54,290 --> 00:00:56,060
This is the step with index zero.

15
00:00:56,060 --> 00:00:57,950
This is the step at index one.

16
00:00:57,950 --> 00:01:00,260
And this is the step at index two.

17
00:01:00,260 --> 00:01:02,270
And then this is the destination.

18
00:01:02,270 --> 00:01:07,400
Notice that the destination is beyond the last index in the cost array.

19
00:01:07,520 --> 00:01:15,260
And the expected output in this case is equal to two because we can start at this step over here.

20
00:01:15,260 --> 00:01:21,050
Because in the question it's mentioned that we can either start from the step with index zero or the

21
00:01:21,050 --> 00:01:22,100
step with index one.

22
00:01:22,100 --> 00:01:24,560
So let's say we are starting over here.

23
00:01:24,560 --> 00:01:26,780
That is at the step with index one.

24
00:01:26,780 --> 00:01:30,050
And then we'll pay this amount which is two.

25
00:01:30,050 --> 00:01:32,030
And we can use this step.

26
00:01:32,030 --> 00:01:35,210
And we can either go one step or two steps.

27
00:01:35,210 --> 00:01:40,070
But it's good to use two steps because that will ensure that we have reached the destination.

28
00:01:40,070 --> 00:01:45,950
So that's why the total cost involved in this case would be two, because we're just using this step

29
00:01:45,950 --> 00:01:46,490
over here.

30
00:01:46,490 --> 00:01:50,840
So we will have to pay two and we will be able to reach the destination.

31
00:01:50,840 --> 00:01:55,760
Now, what are a few other ways in which we could have reached the top or the destination?

32
00:01:55,760 --> 00:02:03,380
We could have started at this step over here with index zero, and we could first take two steps and

33
00:02:03,380 --> 00:02:04,670
then take one step.

34
00:02:04,670 --> 00:02:07,820
So what would be the total cost involved in this case?

35
00:02:07,820 --> 00:02:09,710
Because we are using this step.

36
00:02:09,710 --> 00:02:16,310
And this step will have to pay the cost at these two indices which is one and three.

37
00:02:16,310 --> 00:02:20,090
So the total cost would be one plus three which is equal to four.

38
00:02:20,120 --> 00:02:20,630
Okay.

39
00:02:20,630 --> 00:02:27,110
Now another way in which we could have reached the top could be by first taking one step from this step

40
00:02:27,110 --> 00:02:28,940
and then taking two steps.

41
00:02:29,270 --> 00:02:29,690
Okay.

42
00:02:29,690 --> 00:02:32,510
So in this case we're using this step over here.

43
00:02:32,510 --> 00:02:34,370
And we're using this step over here.

44
00:02:34,370 --> 00:02:38,750
So we would have to pay one plus two which is a total of three.

45
00:02:39,330 --> 00:02:42,780
So in this way, you can see there are multiple ways to reach the top.

46
00:02:42,780 --> 00:02:50,190
And the question asks us to identify the path which would require the minimum amount to be paid.

47
00:02:50,190 --> 00:02:53,010
And then we'll have to output that particular amount.

48
00:02:53,010 --> 00:02:54,900
So this is the question at hand.

49
00:02:54,930 --> 00:02:58,980
Now in the next video let's go ahead and see how we can solve this.
