3660. Jump Game IX Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [3660] Jump Game IX
3 *
4 * You are given an integer array nums.
5 * From any index i, you can jump to another index j under the following rules:
6 * 
7 * 	Jump to index j where j > i is allowed only if nums[j] < nums[i].
8 * 	Jump to index j where j < i is allowed only if nums[j] > nums[i].
9 * 
10 * For each index i, find the maximum value in nums that can be reached by following any sequence of valid jumps starting at i.
11 * Return an array ans where ans[i] is the maximum value reachable starting from index i.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [2,1,3]</span>
16 * Output: <span class="example-io">[2,2,3]</span>
17 * Explanation:
18 * 
19 * 	For i = 0: No jump increases the value.
20 * 	For i = 1: Jump to j = 0 as nums[j] = 2 is greater than nums[i].
21 * 	For i = 2: Since nums[2] = 3 is the maximum value in nums, no jump increases the value.
22 * 
23 * Thus, ans = [2, 2, 3].
24 * 
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [2,3,1]</span>
29 * Output: <span class="example-io">[3,3,3]</span>
30 * Explanation:
31 * 
32 * 	For i = 0: Jump forward to j = 2 as nums[j] = 1 is less than nums[i] = 2, then from i = 2 jump to j = 1 as nums[j] = 3 is greater than nums[2].
33 * 	For i = 1: Since nums[1] = 3 is the maximum value in nums, no jump increases the value.
34 * 	For i = 2: Jump to j = 1 as nums[j] = 3 is greater than nums[2] = 1.
35 * 
36 * Thus, ans = [3, 3, 3].
37 * </div>
38 *  
39 * Constraints:
40 * 
41 * 	1 <= nums.length <= 10^5
42 * 	1 <= nums[i] <= 10^9​​​​​​​
43 * 
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/jump-game-ix/
48// discuss: https://leetcode.com/problems/jump-game-ix/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53    pub fn max_value(nums: Vec<i32>) -> Vec<i32> {
54        vec![]
55    }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63
64    #[test]
65    fn test_3660() {
66    }
67}
68

Back
© 2026 bowen.ge All Rights Reserved.