We see that this problem can be defined by subproblems and have the optimal solution be related (recursively) to those subproblems. Our base cases are clear
We’ll notice that the optimal solution is since we can either move 1 or 2 steps. We could easily represent this as a recurrence relation and complete it with memoization, however, we take a bottom-up dynamic programming approach.
Finally, our return statement has the same logic of choosing the index 0 or 1 which minimizes the cost of the path up.
Note: we can remove the extra memory of and compute everything in , however, to keep consistent and relate it to what I’m learning in COMPSCI 3AC3 @ McMaster, I won’t omit it for understanding purposes.