Back to Practice Dashboard
Competitive ProgrammingEasy
Minimum Jumps
Learn how to solve the 'Minimum Jumps' problem. This detailed resource details brute force and optimized approaches.
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?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.