Magicsheet logo

Jump Game

Medium
57.5%
Updated 6/1/2025

Jump Game

1. What is this problem about?

The Jump Game interview question asks if you can reach the last index of an array starting from the first. Each element in the array nums[i] represents your maximum jump length from that position. You don't have to jump the full distance; you can jump any distance from 0 up to nums[i].

2. Why is this asked in interviews?

This is a classic problem at Meta, Amazon, and Adobe. It tests your ability to simplify a problem using a Greedy approach. While it can be modeled as a search or DP problem, the greedy solution is O(N)O(N) and extremely elegant. It evaluates your ability to maintain a global state (the furthest reachable point) while scanning through an array.

3. Algorithmic pattern used

This is a quintessential Greedy interview pattern problem.

  1. Furthest Point: Maintain a variable maxReach initialized to 0.
  2. Iterate: Loop through the array from left to right.
  3. Reachability Check: If your current index i is greater than maxReach, you can't even reach this index, so return false.
  4. Update: Update maxReach = max(maxReach, i + nums[i]).
  5. Success: If maxReach ever becomes n1\geq n - 1, return true.

4. Example explanation

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

  1. i=0i=0: maxReach = max(0, 0+2) = 2.
  2. i=1i=1: 121 \leq 2, so we can reach it. maxReach = max(2, 1+3) = 4.
  3. i=2i=2: 242 \leq 4, so we can reach it. maxReach = max(4, 2+1) = 4.
  4. maxReach is 4, which is the last index. Result: True. nums = [3, 2, 1, 0, 4]
  5. i=0,1,2i=0, 1, 2 work. maxReach becomes 3.
  6. i=3i=3: maxReach = max(3, 3+0) = 3.
  7. i=4i=4: 4>34 > 3. We can never reach the last index. Result: False.

5. Common mistakes candidates make

  • Over-complicating with DP: Writing a O(N2)O(N^2) DP solution when the greedy O(N)O(N) one is much faster and simpler.
  • Forgetting the "can't reach" check: Failing to stop the loop if i > maxReach.
  • Off-by-one: Mistakes in checking the target index boundary.

6. Interview preparation tip

Whenever a problem asks "is it possible to reach X," first check if a Greedy strategy can track the "boundary of possibility." This often avoids the need for complex recursion or large DP tables. This is a core Array interview pattern.

Similar Questions