🎙 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 2 of 10

What does this print? (code)

What does this print?

def ways(n):
    a, b = 1, 1
    for _ in range(2, n + 1):
        a, b = b, a + b
    return b
print(ways(6))
  1. A.8
  2. B.21
  3. C.13
  4. D.6
Answer & explanation

Correct answer: 13

The sequence for n = 1..6 is 1, 2, 3, 5, 8, 13.

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 →