1123. Jump Game II — Minimum Jumps

EasyDynamic Programming1D DPGreedy

Given an array nums where nums[i] is the maximum jump length from index i (assume the last index is always reachable), return the minimum number of jumps to reach the last index from index 0. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the minimum number of jumps.

Examples

Example 1
Input: {"nums":[2,3,1,1,4]}
Output: 2
Explanation: Jump to index 1, then to the end.
Example 2
Input: {"nums":[2,3,0,1,4]}
Output: 2
Explanation: Two jumps suffice.
Example 3
Input: {"nums":[0]}
Output: 0
Explanation: Already at the end.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →