FastPrepMaximum Score with K-step Jumps

Maximum Score with K-step Jumps

Rippling logoRippling● MediumINTERNFULLTIMEPHONE SCREEN
Learn

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) → int

Examples

Example 1

nums = [1,-1,-2,4,-7,3]k = 2return = 7

Visit indices 0, 1, 3, and 5 for score 1 - 1 + 4 + 3 = 7.

Example 2

nums = [-8]k = 1return = -8

The start is already the destination and its value still counts.

Constraints

  • 1 <= n == nums.length <= 20000.
  • 1 <= k <= n.
  • -10000 <= nums[i] <= 10000.

More Rippling problems

See Rippling hiring insights
public int maximumJumpScore(int[] nums, int k) {
    // write your code here
}
nums[1,-1,-2,4,-7,3]
k2
expected7
Checking account…