Count the ways to climb five steps taking one or two at a time.
Acceptance criteria
- 1.#out should show ways 8.
DSA Tutorial · Dynamic Programming
These 10 tasks go with the Dynamic Programming Explained chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Dynamic programming has an intimidating name for a simple idea: work something out once, write it down, and look it up next time instead of working it out again.” .
1.Climbing stairsexercise · easy · 10 min
Count the ways to climb five steps taking one or two at a time.
Passes when: #out should show ways 8.
2.Bottom-up tableexercise · easy · 10 min · practice plan
Fill a table iteratively and show the answer for six steps.
Passes when: #out should show ways 13.
3.Rolling variablesexercise · easy · 10 min · practice plan
Use two variables instead of a table and show the answer for six.
Passes when: #out should show ways 13.
4.Count cache hitsexercise · easy · 10 min · practice plan
Report how many distinct subproblems a memoised run over five stores.
Passes when: #out should show stored 3.
5.House robberexercise · medium · 10 min · practice plan
Take the best non-adjacent total from four houses.
Passes when: #out should show best 6.
6.Fix the memo never filledbug fix · easy · 8 min
A cache that is never written to cannot save any work.
Passes when: #out should show stored 3.
7.Fix the wrong base casebug fix · easy · 8 min · practice plan
Two steps can be climbed two ways, not one.
Passes when: #out should show ways 8.
8.Fix the table filled from the wrong endbug fix · easy · 8 min · practice plan
Reading ahead of the current cell uses values not yet computed.
Passes when: #out should show ways 13.
9.Fix the rolling update overwritingbug fix · medium · 8 min · practice plan
Assigning one variable before the other loses the value still needed.
Passes when: #out should show ways 13.
10.Fix the robber taking neighboursbug fix · easy · 8 min · practice plan
Adding every house ignores the no-adjacent rule.
Passes when: #out should show best 6.
Between them these tasks cover Memoisation, Base cases and Overlapping subproblems.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.