3282. Reach End of Array With Max Score
3282. Reach End of Array With Max Score
Description
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.
Example 1:
1 | Input: nums = [1,3,1,5] |
Explanation:
First, jump to index 1 and then jump to the last index. The final score is 1 * 1 + 2 * 3 = 7
.
Example 2:
1 | Input: nums = [4,3,1,3,2] |
Explanation:
Jump directly to the last index. The final score is 4 * 4 = 16
.
Constraints:
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5
Hints/Notes
- 2024/09/05
- Draw the metric, it’s the sum of rectangles
- 0x3F’s solution(checked)
- Weekly Contest 414
Solution
Language: C++
1 | class Solution { |