ORIGINAL CODING QUESTION
Cheapest certification ladder climb
A certification ladder has n rungs numbered 0 to n-1, each with a fee. You may begin on rung 0 or rung 1 for free. Each move goes up one or two rungs, and you pay the fee of the rung you leave. Return the minimum total fee needed to reach position n, just above the last rung.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n rung fees.
Constraints
1 ≤ n ≤ 200; 0 ≤ fee ≤ 100.
Example 1
Input
4 5 9 3 8
Output
8
Start on rung 0, pay 5 to jump to rung 2, then pay 3 to jump past the top: 8.
Example 2
Input
2 7 4
Output
4
Start on rung 1 and pay 4 to step past the top.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Position n can be entered from position n-1 or n-2.
Hint 2
best[i] = min(best[i-1] + fee[i-1], best[i-2] + fee[i-2]) with best[0] = best[1] = 0.
Hint 3
Two rolling variables are enough.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →