board with m rows and n columns of positive numbers. A token moves only down or right, and a single move may skip over any number of cells: from (i, j) it can go to any (i', j) with i' > i or to any (i, j') with j' > j.
A move from a cell holding c1 to a cell holding c2 scores c2 - c1 points, which may be negative. You may start on any cell, but you must make at least one move.
Return the largest total score you can collect.board=[[6, 2, 8], [5, 1, 4], [9, 3, 7]] → 6
Start on the 1 (row 1, column 1), jump right to the 4 (+3), then down to the 7 (+3), for 6 in total. Jumping straight from 1 to 7 gives the same 6, and nothing beats it.
board=[[10, 8], [7, 3]] → -2
Every jump lands on a smaller number. The least painful single move is 10 → 8, worth −2, and that is the maximum.
board=[[4, 4], [4, 4]] → 0
All values are equal, so every move scores 0.
m, n ≤ 1000m * n ≤ 10⁵board[i][j] ≤ 10⁵board=[[6, 2, 8], [5, 1, 4], [9, 3, 7]]
6
Run checks the first 3 tests in your browser. Submit checks all 79 tests on the server, hidden ones included.