Maximum Score with K-step Jumps
Problem statement
Start at index 0 of nums and reach index n - 1. From index i, you may jump to any index from i + 1 through min(n - 1, i + k), inclusive.
Your score is the sum of the values at all visited indices, including both the starting and ending indices. Return the greatest possible score. You must reach the ending index even if the best score is negative.
Function
maximumJumpScore(nums: int[], k: int) → intExamples
Example 1
nums = [1,-1,-2,4,-7,3]k = 2return = 7Visit indices 0, 1, 3, and 5 for score 1 - 1 + 4 + 3 = 7.
Example 2
nums = [-8]k = 1return = -8The start is already the destination and its value still counts.
Constraints
1 <= n == nums.length <= 20000.1 <= k <= n.-10000 <= nums[i] <= 10000.