670. Minimum Cost Jump Game (Monotonic Queue DP)

HardStackDequeDynamic Programming

Starting at index 0, from index i you may jump to any index in [i+1, i+k]. Landing on index i adds nums[i] to your cost. Return the minimum total cost to reach the last index. The input is JSON {nums, k}.

Input: JSON {nums, k}.

Output: Integer — the minimum cost to reach the last index.

Examples

Example 1
Input: {"nums":[1,-1,-2,4,-7,3],"k":2}
Output: -6
Explanation: An optimal path minimizes cost.
Example 2
Input: {"nums":[5],"k":1}
Output: 5
Explanation: Already at the end.
Example 3
Input: {"nums":[3,2,1],"k":1}
Output: 6
Explanation: Must land on every index.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →