Length of the Longest Descent 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
JavaScript (ES7), &nbsp;106 103 102&nbsp; 98 bytes



f=(m,n=b=-1,x,y,p)=&gt;m.map((r,Y)=&gt;r.map((v,X)=&gt;(x-X)**2+(y-Y)**2-1|v/p?b=n&lt;b?b:n:f(m,n+1,X,Y,v)))|b


Try it online!

Commented

f = (                        // f = recursive function taking:
  m,                         //   m[]  = input matrix
  n = b = -1,                //   n    = length of the current path; b = best length so far
  x, y,                      //   x, y = coordinates of the previous cell
  p                          //   p    = value of the previous cell
) =&gt;                         //
  m.map((r, Y) =&gt;            // for each row r[] at position Y in m[]:
    r.map((v, X) =&gt;          //   for each value v at position X in r[]:
      (x - X) ** 2 +         //     compute the squared Euclidean distance
      (y - Y) ** 2           //     between (x, y) and (X, Y)
      - 1                    //     if A) the above result is not equal to 1
      | v / p ?              //     or B) v is greater than or equal to p:
        b = n &lt; b ? b : n    //       end of path: update b to n if n &gt;= b
      :                      //     else:
        f(m, n + 1, X, Y, v) //       do a recursive call
    )                        //   end of inner map()
  ) | b                      // end of outer map(); return b


How?

During the first iteration, \$x\$, \$y\$ and \$p\$ are all undefined and both tests (A and B in the comments) evaluate to NaN, which triggers the recursive call. Therefore, all cells are considered as a possible starting point of the path.