Maximum Array Hopping Score II - 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 any index j where 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,3,6,4,5]
›
Output:
22
💡 Note:
Optimal path: 0→2→4. Jump from index 0 to 2: (2-0)*6=12. Jump from index 2 to 4: (4-2)*5=10. Total score: 12+10=22.
Example 2 — Simple Case
$
Input:
nums = [2,5,3]
›
Output:
8
💡 Note:
We can jump 0→1→2 for score (1-0)*5+(2-1)*3 = 5+3 = 8, or jump 0→2 directly for score (2-0)*3 = 6. The maximum is 8.
Example 3 — Two Elements
$
Input:
nums = [7,2]
›
Output:
2
💡 Note:
Only one jump possible: from index 0 to index 1, score = (1-0)*2 = 2.
Constraints
- 2 ≤ nums.length ≤ 1000
- -1000 ≤ nums[i] ≤ 1000
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code