[LeetCode] Maximum Array Hopping Score II

3221. Maximum Array Hopping Score II

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.

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
long long maxScore(vector<int>& nums) {
long long res = 0;
int best = 0;
for(int i = nums.size() - 1; i >= 0; i--) {
best = max(best, nums[i]);
res += best;
}
return res - best;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/11/22/PS/LeetCode/maximum-array-hopping-score-ii/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.