ProgrammingHard

A grid DP that counts right/down paths for 1000 x 1000 cells should use what memory layout to stay small?

  1. A. Two rolling rows of ints, O(columns) memory, updated row by row
  2. B. A full 1000 x 1000 int table that is never freed, about 4 MB
  3. C. A table indexed by path length, about 10^9 entries
  4. D. A recursive function with no memo, using the stack only

Correct answer: A. Two rolling rows of ints, O(columns) memory, updated row by row

Each row depends only on the previous one, so two rows suffice. A full table is only about 4 MB, but the rolling form is cleaner, and the recursive form is exponential.

More C Programming questions

Exams that ask this topic