Back to May Back to Year 2026
MEDIUM 07 May 2026 View on LeetCode

3660. Jump Game IX

</> Solution

/**
 * Problem: LeetCode 3660 - Jump Game IX
 * Difficulty: Medium
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public int[] maxValue(int[] nums) {
        int n = nums.length;
        int[] preMax = new int[n];
        preMax[0] = nums[0];
        for (int i = 1; i < n; i++) {
            preMax[i] = Math.max(preMax[i - 1], nums[i]);
        }

        int[] ans = new int[n];
        int sufMin = Integer.MAX_VALUE;
        for (int i = n - 1; i >= 0; i--) {
            ans[i] = (preMax[i] > sufMin) ? ans[i + 1] : preMax[i];
            sufMin = Math.min(sufMin, nums[i]);
        }

        return ans;
    }
}

TIME COMPLEXITY

O(N)

SPACE COMPLEXITY

O(N)

TOPICS

Array Dynamic Programming Greedy