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

What does this print? (code)

What does this print?

from bisect import bisect_left
tails = []
for x in [3, 1, 4, 1, 5, 9, 2, 6]:
    k = bisect_left(tails, x)
    if k == len(tails):
        tails.append(x)
    else:
        tails[k] = x
print(len(tails))
  1. A.3
  2. B.5
  3. C.6
  4. D.4
Answer & explanation

Correct answer: 4

One longest increasing subsequence is 1, 4, 5, 9 (or 1, 4, 5, 6), length 4.

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 →