You're given an array of integers nums and need to find the maximum score by hopping through the array from start to finish. Starting at index 0, you can jump to any index j where j > i (current position).
Each jump from index i to index j gives you a score of (j - i) * nums[j]. The longer the jump and the larger the destination value, the higher your score!
Goal: Find the maximum total score you can achieve by making optimal jumps until you reach the last element.
Example: For array [1, 5, 2, 3], jumping from index 0 directly to index 1 gives score (1-0) * 5 = 5, then from index 1 to index 3 gives score (3-1) * 3 = 6, for a total of 11.
Input & Output
Visualization
Time & Space Complexity
Each element is pushed and popped from stack at most once
Stack can contain up to n elements in worst case
Constraints
- 2 โค nums.length โค 105
- 1 โค nums[i] โค 106
- You must start at index 0 and can only jump forward
- You must reach the last index of the array