Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

Grid [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8], [9, 7, 9, 3]]. Starting from any cell in the top row, each step goes to the cell directly below or diagonally below-left or below-right (staying in the grid). What is the maximum sum of a path that reaches the bottom row?

  1. A. 30
  2. B. 9
  3. C. 27
  4. D. 28

Correct answer: C. 27

Row-by-row DP: each cell takes its value plus the best of the three cells above it that are inside the grid. Starting from a single large cell, or going straight down, misses the diagonal options.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic