Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

A gold mine is the grid [[1, 3, 3], [2, 1, 4], [0, 6, 4]]. You start in any cell of the LEFT column and move one column to the right each step, going to the cell up-right, right, or down-right (within the grid). What is the maximum total gold you can collect?

  1. A. 9
  2. B. 14
  3. C. 23
  4. D. 12

Correct answer: D. 12

Backward DP from the right column: best[r][c] = g[r][c] + max best of the three reachable cells in the next column. Starting from the largest left-column cell greedily can miss a better path through a smaller start.

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

Exams that ask this topic