Problems › Greedy algorithms

Jump Game

Difficulty: Medium · Topic: Greedy algorithms

nums[i] is the maximum jump length from index i. Starting at index 0, return True if you can reach the last index. Greedily track the furthest index reachable so far; if you ever stand beyond it, you're stuck.

Examples

can_jump([2,3,1,1,4])
→ true

0→1→4.

can_jump([3,2,1,0,4])
→ false

You get stuck at index 3.

Target complexity: time O(n), space O(1)

Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.

Learn the idea first: the lesson for this problem.

More Greedy algorithms problems