Competitive ProgrammingEasy

Minimum Jumps

Detailed guide and Python implementation for the 'Minimum Jumps' problem.

Problem Statement

Easy

Write a function min_jumps(arr) that finds the minimum number of jumps to reach the last index of arr starting from index 0. Each element in the array represents the maximum jump length from that position. If it is impossible to reach the last index, return -1.

Constraints
  • 1 <= len(arr) <= 10^4
  • 0 <= arr[i] <= 10^4

Examples

Example 1
Input
min_jumps([1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9])
Output
3
Explanation

Jump from index 0 to 1 (value 3), then jump to index 4 (value 9), and then jump to the last index.

Example 2
Input
min_jumps([1, 1, 1, 1, 1])
Output
4
Explanation

Jump one by one from start to end, requiring 4 jumps.

Need a Hint?
Consider using Dynamic Programming-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.