Data Structures & AlgorithmsHardLeetCode-style · Codeforces Div2 C

A square matrix is [[2, 1, 3], [6, 5, 4], [7, 8, 9]]. A falling path starts in row 0 and goes down one row per step, moving to the cell directly below or diagonally left or right (column changes by at most 1). What is the minimum possible sum of the values on a falling path?

  1. A. 13
  2. B. 12
  3. C. 6
  4. D. 14

Correct answer: A. 13

Row-by-row DP: each cell gets its value plus the minimum of the (up to three) cells above it. Walking greedily from the smallest top value is a trap: the smallest start can force a large value in the next row.

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

Exams that ask this topic