Dodomeki
Sign in

86. Minimum Jumps

Medium

You start at the first position of alcances, and each value indicates the maximum jump length allowed. Return the minimum number of jumps needed to reach the end. The input guarantees that the destination is reachable.

Example 1
Input: alcances = [2, 3, 1, 1, 4]
Output: 2
Example 2
Input: alcances = [2, 3, 0, 1, 4]
Output: 2
Constraints
  • 1 <= alcances.length <= 10^5
  • 0 <= alcances[i] <= 10^5
  • The destination is always reachable.
ArraysGreedy
Caso 1
alcances =
[2,3,1,1,4]
Expected =
2
Caso 2
alcances =
[2,3,0,1,4]
Expected =
2

Run checks these 2 cases. Submit runs all 6, including hidden ones.