Data Structures & AlgorithmsVery hardCodeforces Div2 D · LeetCode-style

Grid values [[9, 9, 4], [6, 6, 8], [2, 1, 1]]. A path moves to one of the four neighbouring cells (up, down, left or right) each step, and the values along the path must strictly increase. What is the length (number of cells) of the longest such path?

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

Correct answer: D. 4

Memoised DFS over cells, where each cell's answer is 1 plus the best strictly larger neighbour. Restricting moves to right and down, a common shortcut, misses paths that go left or up.

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

Exams that ask this topic