Your task is to determine the length of the longest descent down a "mountain" represented as a grid of integer heights. A "descent" is any path from a starting cell to orthogonally adjacent cells with strictly decreasing heights (i.e. not diagonal and not to the same height). For instance, you can move from 5-4-3-1 but not 5-5-4-3-3-2-1. The length of this path is how many cell movements there are from the starting cell to the ending cell, thus 5-4-3-1 is length 3.
You will receive a rectangular grid as input and you should output an integer indicating the longest descent.
Examples
1 2 3 2 2
3 4 5 5 5
3 4 6 7 4
3 3 5 6 2
1 1 2 3 1
The length of the longest descent down this mountain is 5. The longest path starts at the 7, moves left, up, left, up, and then left (7-6-5-4-2-1). Since there are 5 movements in this path, the path length is 5.
They might be all the same number.
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Since this height map is flat, the longest descent is 0. (not 19, since the path sequence must be strictly descending)
Height maps can be made up of larger numbers than single-digit numbers.
10 12 13 14 15 15
17 14 15 15 15 16
18 20 21 15 15 15
21 14 10 11 11 15
15 15 15 15 15 15
The longest path here is of length 6. (21, 20, 18, 17, 14, 12, 10)
...And even bigger numbers are fine too.
949858 789874 57848 43758 387348
5848 454115 4548 448545 216464
188452 484126 484216 786654 145451
189465 474566 156665 132645 456651
985464 94849 151654 151648 484364
The longest descent here is of length 7. (786654, 484216, 484126, 474566, 156665, 151654, 151648, 132645)
Rules and Notes
- Grids may be taken in any convenient format. Specify your format in your answer.
- You may assume the height map is perfectly rectangular, is nonempty, and contains only positive integers in the signed 32-bit integer range.
- The longest descent path can begin and end anywhere on the grid.
- You do not need to describe the longest descent path in any way. Only its length is required.
- Shortest code wins