In a browser platform game, a character climbs a column of ledges numbered from 0. Jumping off ledge i costs cost[i] energy, and each jump goes up one or two ledges. The character may start on ledge 0 or ledge 1 for free.
The goal is the top, one place above the last ledge. Write cheapestClimb(cost) that returns the least total energy needed to reach the top.
Input: cost = [12,18,25] Output: 18
Start on ledge 1, pay 18, and jump two ledges to the top.
Input: cost = [2,50,2,2,2,50,2,50,2] Output: 10
Jump off five ledges that cost 2 each and never touch a ledge that costs 50.
2 <= cost.length <= 10000 <= cost[i] <= 999Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #491 Cheapest Hop to the Top Ledge. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.