Another LeetCode problem.
Given an
MxNmatrix of numbers, find the longest path of strictly increasing numbers.
So for example in this matrix:
| 9 | 9 | 4 |
| 6 | 6 | 8 |
| 2 | 1 | 1 |
You can start with the 1 in the bottom center, go left to the two, then up to the 6, and 9. That’s the longest path, so return a 4.
In this 3x3 case, it’s really easy to just brute force. Calculate all possible paths. An upper bound would be visiting every node exactly once, so \sum_{i=1}^9 \binom{9}{i} = 511
(choose n elements for each of 1 to 9 cases). Not so bad. But if you have a 10x10 matrix, that’s already 1e30–which is freaking gigantic. So we need to do better.
