561. Maximum Array Hopping Score II

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

Each hop must follow these rules:

  • You can jump from index i to any index j > i.
  • The score for a jump is calculated as: (j - i) * nums[j].

Return the maximum score achievable.

Example 1:

Input: nums = [2, 6, 9]

Output: 18

Explanation: There are two possible ways to reach the last element:

0 → 1 → 2, with a score of (1 - 0) * 6 + (2 - 1) * 9 = 15.

0 → 2, with a score of (2 - 0) * 9 = 18.

The maximum score is 18.

Example 2:

Input: nums = [3, 7, 4, 10, 12, 2, 5]

Output: 58

Explanation: We can take the path 0 → 4 → 6 to maximize the score:

(4 - 0) * 12 + (6 - 4) * 5 = 58.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [5, 1, 8, 2, 7, 3, 10]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 2 ≤ nums.length ≤ 105
  • 1 ≤ nums[i] ≤ 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
long long maxScore(vector<int>& nums) {
}
};
 
Test Case

Input:

Nums