Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

A grid has 3 rows and 4 columns with these values (top to bottom): 1832 3673 2187 A path moves between side-adjacent cells (up, down, left or right) and each next cell must have a strictly larger value than the current cell. What is the largest number of cells on such a path?

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

Correct answer: B. 6

A memoised DFS from every cell, moving only to strictly larger neighbours, finds the 6-cell path 1 → 2 → 3 → 6 → 7 → 8. Restricting moves to right and down gives 5, 12 is every cell, and 3 is the best run inside one row (3, 6, 7).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic