i holds points[i], which may be negative. You start on cell 0 and want to reach the last cell. Each jump moves you forward by 1, 2, ..., reach cells without leaving the row.
The score of a route is the sum of points on every cell you land on, including the first and the last. Return the highest possible score.points=[2, -4, 5, -1, -3, 6], reach=2 → 12
The best path is 0 → 2 → 3 → 5: 2 + 5 + (-1) + 6 = 12. Going from 2 straight to 5 is three steps, which is too far.
points=[1, -10, -10, 4], reach=3 → 5
One jump from 0 to 3 gives 1 + 4 = 5.
points=[-7], reach=1 → -7
len(points) ≤ 10⁵reach ≤ 10⁵points[i] ≤ 10⁴points=[2, -4, 5, -1, -3, 6], reach=2
12
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.