← 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?
- A.It creates a table of the wrong size
- B.It fills the table with None
- C.All n rows are the same list object, so changing one row changes every row
- 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 →