Ctrl K

Jumps Paid at Takeoff

Medium
The cells of a track are numbered from zero, and cell 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.
Example 1
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.

Example 2
values=[6, 2, 4, 1] → 18

The best move is one jump from the start to the end: 3 · 6 = 18.

Example 3
values=[9] → 0

We already stand on the last cell, no jumps needed, so the score is 0.

Constraints
  • 1 ≤ len(values) ≤ 10⁵
  • 1 ≤ values[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Boards Holding Water MediumFewest Jumps to the End MediumReach the Last Cell MediumAs Many Trades as You Like MediumWhere to Start the Lap Medium
loading Python…
Input
values=[2, 5, 1, 1, 3]
Expected
17

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