LeetCode 329 Longest Increasing Path in a Matrix - Why Naive Fails

The trap

DFS from every cell, tracking the longest path from each.

Without memoization, you recompute paths from the same cell multiple times. Overlapping subproblems make this exponential.

Can you reuse computed results?