Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: A 3×3 matrix is [[2,1,3],[6,5,4],[7,8,9]]. A falling path moves from a cell in row r to a cell in row r+1 in the same column or one column to the left or right. What is the minimum sum of a falling path that starts in row 0 and ends in row 2?

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

Correct answer: D. 13

Row by row, each cell adds the minimum of its up-to-three parents: the best paths are 1 → 4 → 8 or 1 → 5 → 7 = 13. Using max gives 17, staying in one column gives 1 + 5 + 8 = 14, and adding the row minima while ignoring adjacency gives 1 + 4 + 7 = 12.

More Coding Interview Problems questions

Exams that ask this topic