i holds the number values[i]. You start on cell 0 and want to reach the last cell. You may only jump forward, to any cell with a larger index.
A jump from cell i to cell j earns (j - i) * values[i] points: the jump length times the number on the cell you took off from.
Return the largest total score you can collect on your way to the last cell.values=[2, 5, 1, 1, 3] → 17
Jump from 0 to 1 for 1 · 2 = 2, then straight to the end from 1 for 3 · 5 = 15. Total 17.
values=[6, 2, 4, 1] → 18
The best move is one jump from the start to the end: 3 · 6 = 18.
values=[9] → 0
We already stand on the last cell, no jumps needed, so the score is 0.
values=[2, 5, 1, 1, 3]
17
Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.