Reach End of Array With Max Score - Problem
You are given an integer array nums of length n. Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than your current index.
The score for a jump from index i to index j is calculated as (j - i) * nums[i].
Return the maximum possible total score by the time you reach the last index.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,3,2,5]
›
Output:
7
💡 Note:
Jump from index 0 to 2 (score = 2×1 = 2), then from index 2 to 3 (score = 1×2 = 2). Total = 4. But optimal is 0→2→3: (2×1) + (1×2) = 4, or 0→1→3: (1×1) + (2×3) = 7
Example 2 — Two Elements
$
Input:
nums = [3,4]
›
Output:
3
💡 Note:
Only one jump possible from index 0 to 1: score = (1-0) × 3 = 3
Example 3 — Decreasing Array
$
Input:
nums = [5,3,1]
›
Output:
10
💡 Note:
Best strategy is to jump directly from 0 to 2: score = (2-0) × 5 = 10
Constraints
- 2 ≤ nums.length ≤ 105
- -106 ≤ nums[i] ≤ 106
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code