LC 45 — Problem

You are given a 0-indexed array nums of length n. You are initially at nums[0]. Each element nums[i] represents the maximum jump length from index i. Return the minimum number of jumps to reach nums[n - 1]. The input guarantees you can always reach the last index.

Input: nums = 23114
Output: 2

Explanation: jump 1 step from index 0 to 1, then 3 steps to the last index.

Phase 1: Can you prove 2 jumps is the minimum?

Here is nums = [2, 3, 1, 1, 4]. Each value tells you the maximum distance you can jump forward. Can you find a path from the start to the end?

FIG. 1 — NUMS = [2, 3, 1, 1, 4]
nums
2
0
3
1
1
2
1
3
4
4