Skip to main content

18. Jump Game

mediumAsked at Adobe

Given an array where each element is the maximum jump length from that position, determine if you can reach the last index from index 0. Adobe uses this to test greedy reasoning and forward-reachability tracking — a pattern that appears in animation timeline reachability and workflow-state feasibility checks.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Adobe loops.

  • LeetCode Discuss (2025-10)Adobe candidates report greedy array problems including jump game in phone and onsite rounds.
  • Glassdoor (2026-01)Adobe SDE-II reports greedy optimization questions alongside standard array problems.

Problem

You are given an integer array nums. You are initially positioned at the first index of the array. Each element nums[i] represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise.

Constraints

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

Examples

Example 1

Input
nums = [2,3,1,1,4]
Output
true

Explanation: Jump 1 to index 1, then 3 to the last index.

Example 2

Input
nums = [3,2,1,0,4]
Output
false

Explanation: Index 3 always has value 0; you get stuck.

Approaches

1. BFS / DP boolean array

Use a dp array where dp[i] = true if index i is reachable. Iterate from the start, mark all reachable positions.

Time
O(n^2)
Space
O(n)
function canJump(nums) {
  const n = nums.length;
  const reachable = Array(n).fill(false);
  reachable[0] = true;
  for (let i = 0; i < n; i++) {
    if (!reachable[i]) continue;
    for (let j = 1; j <= nums[i]; j++) {
      if (i + j < n) reachable[i + j] = true;
    }
  }
  return reachable[n - 1];
}

Tradeoff: O(n^2) worst case due to the inner loop; O(n) space. Adobe will ask you to reduce to O(n) time.

2. Greedy max-reach

Track the maximum index reachable at each step. Iterate left to right; if the current index exceeds maxReach, return false (we're stuck). Update maxReach = max(maxReach, i + nums[i]) at each step. If we finish the loop, the last index is reachable.

Time
O(n)
Space
O(1)
function canJump(nums) {
  let maxReach = 0;
  for (let i = 0; i < nums.length; i++) {
    if (i > maxReach) return false;
    maxReach = Math.max(maxReach, i + nums[i]);
    if (maxReach >= nums.length - 1) return true;
  }
  return true;
}

Tradeoff: O(n) time, O(1) space. The greedy invariant: maxReach represents the frontier of reachability. As long as we haven't stepped past the frontier, we keep expanding it. Adobe values the early exit when maxReach hits the last index.

Adobe-specific tips

Adobe interviewers connect this problem to animation keyframe scheduling — can a sequence of actions complete given the maximum step sizes available? The greedy max-reach approach is valued because it mirrors the 'furthest-you-can-go' logic in timeline feasibility. Expect follow-up to Jump Game II (LC 45) asking for the minimum number of jumps.

Common mistakes

  • Returning false when i == maxReach and nums[i] == 0 but i is the last index — you've already reached the end.
  • Not handling the single-element array case — nums = [0] should return true.
  • Confusing 'maximum jump length' with 'exact jump length', making the problem seem like BFS.

Follow-up questions

An interviewer at Adobe may pivot to one of these next:

  • Jump Game II (LC 45): return the minimum number of jumps to reach the last index.
  • What if jumps are exact (not maximum) — does the greedy approach still work?
  • How would you reconstruct the path of jumps taken, not just whether it's possible?

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why does the greedy approach work?

At any index i, the maximum reach is i + nums[i]. We only need to know if we can reach some index j from which we can then reach the end. The maximum reachability frontier captures all useful information without tracking specific paths.

What if nums = [0]?

The loop runs once, i=0 <= maxReach=0, maxReach becomes max(0, 0+0)=0, and 0 >= 0 (length-1), so we return true. Correct — you're already at the last index.

Practice these live with InterviewChamp.AI

Drill Jump Game and other Adobe interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →