Data Structures & Algorithms Greedy Algorithms
💡
Exercise 138

Jump Game II 25 XP Medium

LeetCode Ctrl+Enter Run Ctrl+S Save

Same as Jump Game, but find the minimum number of jumps to reach the end. Guaranteed to be reachable.

Greedy BFS: treat it like levels in BFS. Each 'level' is the range of indices reachable with the same number of jumps.

💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!

📋 Instructions
Find minimum jumps to reach end. nums = [2,3,1,1,4]
Track current_end (end of current level) and farthest (max reachable). When i reaches current_end, jump++ and current_end = farthest.
🧪 Test Cases
Input
jump([2,3,1,1,4])
Expected
2
Test case 1
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.