Class Solution

java.lang.Object
g1601_1700.s1696_jump_game_vi.Solution

public class Solution extends Object
1696 - Jump Game VI.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>k</code>.</p> <p>You are initially standing at index <code>0</code>. In one move, you can jump at most <code>k</code> steps forward without going outside the boundaries of the array. That is, you can jump from index <code>i</code> to any index in the range <code>[i + 1, min(n - 1, i + k)]</code> <strong>inclusive</strong>.</p> <p>You want to reach the last index of the array (index <code>n - 1</code>). Your <strong>score</strong> is the <strong>sum</strong> of all <code>nums[j]</code> for each index <code>j</code> you visited in the array.</p> <p>Return <em>the <strong>maximum score</strong> you can get</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,-1,-2,4,-7,3], k = 2</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong> You can choose your jumps forming the subsequence [1,-1,4,3] (underlined above). The sum is 7.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [10,-5,-2,4,0,3], k = 3</p> <p><strong>Output:</strong> 17</p> <p><strong>Explanation:</strong> You can choose your jumps forming the subsequence [10,4,3] (underlined above). The sum is 17.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [1,-5,-20,4,-1,3,-6,-3], k = 2</p> <p><strong>Output:</strong> 0</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length, k <= 10<sup>5</sup></code></li> <li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxResult

      public int maxResult(int[] nums, int k)