Reach End of Array With Max Score - Problem
Array Jumping Challenge: Maximize Your Score!

You're given an integer array nums of length n, and you need to traverse from the first index (0) to the last index (n-1) by making strategic jumps. Here's the twist: you can only jump forward to indices greater than your current position!

๐ŸŽฏ Scoring System: Each jump from index i to index j earns you (j - i) ร— nums[i] points. The longer your jump and the higher the value at your starting position, the more points you earn!

Goal: Find the maximum possible total score you can achieve by the time you reach the final index.

Example: If nums = [1, 3, 1, 5], jumping from index 1 (value=3) to index 3 (value=5) would score (3-1) ร— 3 = 6 points.

Input & Output

example_1.py โ€” Basic Case
$ Input: nums = [1, 3, 1, 5]
โ€บ Output: 7
๐Ÿ’ก Note: Optimal path: 0โ†’1 (score: 1ร—1=1), then 1โ†’3 (score: 2ร—3=6). Total: 1+6=7. This beats jumping 0โ†’2โ†’3 (1ร—2 + 1ร—1 = 3) or 0โ†’3 directly (3ร—1 = 3).
example_2.py โ€” Decreasing Array
$ Input: nums = [5, 3, 2, 1]
โ€บ Output: 15
๐Ÿ’ก Note: Since values only decrease, we jump directly from start to end: (3-0) ร— 5 = 15 points. No benefit in stopping at intermediate positions.
example_3.py โ€” Single Element
$ Input: nums = [7]
โ€บ Output: 0
๐Ÿ’ก Note: With only one element, we're already at the end, so no jumps are needed and score is 0.

Constraints

  • 1 โ‰ค nums.length โ‰ค 105
  • 1 โ‰ค nums[i] โ‰ค 105
  • You must start at index 0 and reach index n-1
  • You can only jump to indices greater than your current index

Visualization

Tap to expand
๐ŸŽฎ Array Jumping GameSTARTValue: 1Index: 0HIGHValue: 3Index: 1LOWValue: 1Index: 2PEAKValue: 5Index: 3+1 pt+6 pts๐Ÿ† FINISHTotal Score:7 Points!๐Ÿง  Greedy StrategyAlways jump to the next HIGHER platform first!Higher starting values ร— jump distance = More points!
Understanding the Visualization
1
Scan Forward
From current position, look for the next platform with a higher value
2
Strategic Jump
Jump to that higher-value platform to maximize future scoring potential
3
Calculate Score
Add (jump_distance ร— starting_platform_value) to total score
4
Repeat or Finish
Continue strategy or jump directly to end if no higher values remain
Key Takeaway
๐ŸŽฏ Key Insight: The greedy approach works because higher starting values multiply distance gains, so we should always prioritize reaching and staying at high-value positions before making longer jumps.
Asked in
Google 25 Meta 18 Amazon 15 Microsoft 12
38.0K Views
Medium Frequency
~25 min Avg. Time
1.4K Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen