🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Because n is small
  2. B.Each state depends only on the previous two states
  3. C.Because Python lists are slow
  4. 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 →