Skip to main content
Back to problems
#3205
Medium Algorithms

Maximum array hopping score i

Array Dynamic Programming Stack Greedy Monotonic Stack
77.1% acceptance
Mar 31, 2026
28
1
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.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn max_score(nums: Vec<i32>) -> i32 {
    let n = nums.len();
    let mut suffix_max = nums[n - 1];
    let mut result = 0;
    for i in (1..n).rev() {
      suffix_max = suffix_max.max(nums[i]);
      result += suffix_max;
    }
    result
  }
}