#3221
Medium Algorithms Maximum array hopping score ii
Array Stack Greedy Monotonic Stack
59.6% acceptance
Mar 31, 2026
17
3
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)
impl Solution {
pub fn max_score(nums: Vec<i32>) -> i64 {
let n = nums.len();
let mut suffix_max = nums[n - 1] as i64;
let mut result: i64 = 0;
for i in (1..n).rev() {
suffix_max = suffix_max.max(nums[i] as i64);
result += suffix_max;
}
result
}
}