ProgrammingHard

Which 2D DP table declaration is correct for a 1000 x 1000 table of ints in a contest C program?

  1. A. int dp[1001][1001]; declared inside main as a local
  2. B. int dp[1000][1000]; with indices running to 1000
  3. C. int dp[1000001]; indexed as dp[i][j] with i, j in range
  4. D. static int dp[1001][1001];

Correct answer: D. static int dp[1001][1001];

A static array of 1001 x 1001 ints is about 4 MB and lives outside the stack. The local version can overflow the stack, and the 1000 size lacks index 1000.

More C Programming questions

Exams that ask this topic