Jump Game VI

Given an array of scores and a jump limit k, return the maximum score you can obtain when moving from the first index to the last. Pattern focus: Deque for Sliding Window Maximum. Keep the best dynamic programming states in a monotonic deque so each transition looks only at the useful candidates.

Input Format

nums = score array, k = maximum jump length

Output Format

maximum score obtainable at the last index

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • nums, k must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

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

Output:

7

Explanation:

The optimal path accumulates a total score of 7.

Example 2:

Input:

nums = [10,-5,-2,4,0,3]
k = 3

Output:

17

Explanation:

The best route uses high-scoring jumps within the limit.

Loading...
Jump Game VI - Queue Deque DSA Problem