---
# System prepended metadata

title: Untitled

---

### Interview - Maxine Yee

> You are given an array of integers `cost` where `cost[i]` is the cost at the `ith` step on a staircase. Starting at either index `0` OR `1`, you can either climb one or two steps each time. Return the minimum cost to reach the end of the staircase.
Note: You pay the cost at the current step only when moving to the next (i.e. don't need to pay the cost at the last step) — can also ignore this point for simplicity.

Examples:
`Input: cost = [10,15]`

`Output: 10`

`Explanation: Start at 10, take 2 steps, reach the top, pay 10.`

`Input: cost = [10,20,15]`

`Output: 20`

`Explanation: Start at 20, take 2 steps, reach the top, pay 20.`

`Input: cost = [1,100,1,1,_1_,100,1,1,100,1]`

`Output: 6`

`Explanation: Start at 1, take 2 steps, pay 1, take 2 steps, pay 1, take 2 steps, pay 1, take 1 step, pay 1, take 2 steps, pay 1, take 1 step, reach the top, pay 1.`


```javascript=
const minCost = (int[] cost) => {
    return Math.min(minCostFrom(0), minCostFrom(1));
}

```

```javascript=
const minCostFrom = (int[] cost, int startIndex) => {
    if (startIndex >= cost.length) {
        return 0;
    }
    const 1stepCost = minCostFrom(cost, startIndex + 1) + cost[startIndex];
    const 2stepCost = minCostFrom(cost, startIndex + 2) + cost[startIndex];
    return Math.min(1stepCost, 2stepCost);
}

```