Maximum Array Hopping Score I - Problem

Given an array nums, you have to get the maximum score starting from index 0 and hopping until you reach the last element of the array.

In each hop, you can jump from index i to an index j > i, and you get a score of (j - i) * nums[j].

Return the maximum score you can get.

Input & Output

Example 1 — Basic Hopping
$ Input: nums = [1,5,3,9,2]
Output: 29
💡 Note: Optimal path: 0→3→4. Score = (3-0)*9 + (4-3)*2 = 27 + 2 = 29
Example 2 — Minimum Array
$ Input: nums = [5,2]
Output: 2
💡 Note: Only one jump possible: 0→1. Score = (1-0)*2 = 2
Example 3 — Sequential Jumps
$ Input: nums = [1,2,3,4]
Output: 12
💡 Note: Best path: 0→3. Score = (3-0)*4 = 12. Better than 0→1→2→3 which gives 8

Constraints

  • 2 ≤ nums.length ≤ 1000
  • -103 ≤ nums[i] ≤ 103
  • You must start from index 0 and reach the last index

Visualization

Tap to expand
Maximum Array Hopping Score: Find Optimal Jump Path1539201234Jump 0→3Score: (3-0)×9 = 27Jump 3→4Score: (4-3)×2 = 2Score Formula: (destination_index - source_index) × nums[destination]Total Score: 27 + 2 = 29Optimal strategy: Jump far to high-value elements
Understanding the Visualization
1
Input
Array [1,5,3,9,2] with indices 0,1,2,3,4
2
Scoring
Each jump from i to j scores (j-i) × nums[j]
3
Optimal Path
Path 0→3→4 gives maximum score of 29
Key Takeaway
🎯 Key Insight: The score formula (distance × value) makes it profitable to jump far to high-value elements rather than taking many small jumps
Asked in
Amazon 15 Microsoft 12 Google 8 Meta 5
23.4K Views
Medium Frequency
~25 min Avg. Time
847 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