Competitive Programming簡単

Minimum Jumps

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

問題提起

簡単

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.

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

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

解決する準備はできましたか?

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

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。