This problem is a slightly modified version of the famous Google problem (now banned) 'Climb Stairs: https://leetcode.com/problems/climbing-stairs/description/

```
class Solution {
public int minCostClimbingStairs(int[] a) {
int n = a.length;
int prevPrev = a[0], prev = a[1];
for (int i = 2; i < n; i++) {
int cur = a[i] + Math.min(prev, prevPrev);
prevPrev = prev;
prev = cur;
}
//This is the modification
return Math.min(prev, prevPrev);
}
}
```