1696. Jump Game VI Medium

@problem@discussion
#Array#Dynamic Programming#Queue#Sliding Window#Heap (Priority Queue)#Monotonic Queue



1/**
2 * [1696] Jump Game VI
3 *
4 * You are given a 0-indexed integer array nums and an integer k.
5 * You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you can jump from index i to any index in the range [i + 1, min(n - 1, i + k)] inclusive.
6 * You want to reach the last index of the array (index n - 1). Your score is the sum of all nums[j] for each index j you visited in the array.
7 * Return the maximum score you can get.
8 *  
9 * Example 1:
10 * 
11 * Input: nums = [<u>1</u>,<u>-1</u>,-2,<u>4</u>,-7,<u>3</u>], k = 2
12 * Output: 7
13 * Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.
14 * 
15 * Example 2:
16 * 
17 * Input: nums = [<u>10</u>,-5,-2,<u>4</u>,0,<u>3</u>], k = 3
18 * Output: 17
19 * Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.
20 * 
21 * Example 3:
22 * 
23 * Input: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2
24 * Output: 0
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= nums.length, k <= 10^5
30 * 	-10^4 <= nums[i] <= 10^4
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/jump-game-vi/
36// discuss: https://leetcode.com/problems/jump-game-vi/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn max_result(nums: Vec<i32>, k: i32) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_1696() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.