← Quiz: 1D Dynamic Programming Patterns: all 10 questions
Quiz: 1D Dynamic Programming Patterns · Question 9 of 10
Climbing stairs keeps only two variables instead of an array. Why is that allowed?
Climbing stairs keeps only two variables instead of an array. Why is that allowed?
- A.Because n is small
- B.Each state depends only on the previous two states
- C.Because Python lists are slow
- D.It is not allowed; the answer changes
Answer & explanation
Correct answer: Each state depends only on the previous two states
When the recurrence looks back a fixed number of steps, older values can be thrown away: O(1) memory.
Can you get the rest right without peeking?
Take the timed Quiz: 1D Dynamic Programming Patterns quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →