This page uses the site's newer layout, so only the problem statement and the section outline survive in the public payload — open the original for the rest.
Greedy Algorithms
Jump Game II
medium
DESCRIPTION (inspired by Leetcode.com)
Imagine stepping stones across a river. You start on the first stone (index 0) and need to reach the final stone. Each stone has a number indicating the maximum distance you can leap from that position. Find the fewest number of leaps required to reach the end. You may assume a path to the end always exists.
Example 1
Input:
nums = [3, 4, 2, 1, 2, 1]
Output:
2
Explanation: From stone 0, leap to stone 1 (you could go up to 3 stones, but 1 is strategic). From stone 1, leap directly to stone 5 (4 stones forward). Total = 2 leaps.
Example 2
Input:
nums = [1, 2, 1, 1, 1]
Output:
3
Explanation: Leap 0→1, then 1→3, then 3→4. Three leaps total.