Ctrl K

Best Score With Short Jumps

Medium
Points are laid out along a row of cells: cell 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.
Example 1
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.

Example 2
points=[1, -10, -10, 4], reach=3 → 5

One jump from 0 to 3 gives 1 + 4 = 5.

Example 3
points=[-7], reach=1 → -7
Constraints
  • 1 ≤ len(points) ≤ 10⁵
  • 1 ≤ reach ≤ 10⁵
  • -10⁴ ≤ points[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMarket Fruit Bonus MediumMaximum Sum With Short Hops HardFerry Runs From the Depot HardStops With Free Rides HardBest Run on a Ring Medium
loading Python…
Input
points=[2, -4, 5, -1, -3, 6], reach=2
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.