🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: DP on Grids and Strings: all 10 questions

Quiz: DP on Grids and Strings · Question 9 of 10

Why is [[0] m] n a bug for a DP table in Python?

Why is [[0] * m] * n a bug for a DP table in Python?

  1. A.It creates a table of the wrong size
  2. B.It fills the table with None
  3. C.All n rows are the same list object, so changing one row changes every row
  4. D.It is too slow
Answer & explanation

Correct answer: All n rows are the same list object, so changing one row changes every row

Use [[0] * m for _ in range(n)] so each row is a separate list.

Can you get the rest right without peeking?

Take the timed Quiz: DP on Grids and Strings quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →