#55

Jump Game

MediumGreedyHas vizArrayGreedyDynamic Programming

Problem

You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.

Return true if you can reach the last index, or false otherwise.

Example 1

Input: nums = [2,3,1,1,4]

Output: true

Jump 1 step from index 0 to 1, then 3 steps to the last index.

Example 2

Input: nums = [3,2,1,0,4]

Output: false

You always arrive at index 3 with jump length 0.

Constraints

  • 1 <= nums.length <= 10^4
  • 0 <= nums[i] <= 10^5
Loading visualization…

Explanation

Jump Game is a Medium interview problem tagged [Array, Greedy, Dynamic Programming]. The winning approach is typically **Greedy**.

Intuition

When an exchange argument holds, greedy beats heavier DP.

Approach

Sort by a key, then make the locally best choice that preserves a global invariant.

  1. Propose a sort key.
  2. Scan once maintaining state.
  3. Prove no better swap exists—or test counterexamples.

Solution

Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.

Pattern templateGreedy

Edge cases

  • •Empty or single-element input
  • •Duplicates and ties
  • •Maximum constraints / overflow
  • •Disconnected or unreachable states (for graphs)

Complexity

Time: O(n log n) or O(n)

Space: O(n)

Before coding, restate the problem, name the pattern (Greedy), and write the invariant or DP state in one sentence.

Learn the topic

Got it?

Mark #55 Jump Game as understood when the pattern clicks.