Jump Game: Reachability and Minimum Jumps

medium
Unit 17 · Greedy & Trees0/3 to milestone

nums[i] is the maximum jump length from position i. Starting at index 0, implement in O(n):

  • can_reach_end(nums): whether the last index is reachable
  • min_jumps(nums): the minimum number of jumps to reach the last index, or -1 if impossible. Think of it as BFS where each "level" is the range of indices reachable with a given number of jumps.
#greedy#arrays#bfs2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Jump Game: Reachability and Minimum Jumps · TechGradify