Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: On a 3×3 matrix [[9,9,4],[6,6,8],[2,1,1]], a strictly increasing path moves up, down, left or right between adjacent cells with increasing values. What is the length (number of cells) of the longest such path?

  1. A. 5
  2. B. 4
  3. C. 3
  4. D. 6

Correct answer: B. 4

Memoised DFS over strictly increasing neighbour edges gives the longest path from each cell. Using non-strict comparisons allows equal values and overcounts.

More Coding Interview Problems questions

Exams that ask this topic