#1696
Jump Game VI
specialist · 920 · lc medium +32 · verified · 46.4% accepted · 3,552 likes · top 31%
Description
You are given a 0-indexed integer array nums and an integer k. Starting at index 0, each move lets you advance between 1 and k positions (from index i you can jump to any index in [i + 1, min(n - 1, i + k)]). Your score is the sum of nums[j] for every index j you visit on your way to index n - 1. Return the highest score achievable.
Example 1:
Input: nums = [1,-1,-2,4,-7,3], k = 2
Output: 7
Explanation: You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.
Example 2:
Input: nums = [10,-5,-2,4,0,3], k = 3
Output: 17
Explanation: You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.
Example 3:
Input: nums = [1,-5,-20,4,-1,3,-6,-3], k = 2
Output: 0
Code
1
2
3