MEDIUM
ArrayDynamic ProgrammingGreedy
Updated Sep 2026

Jump Game

Asked at Oracle

Problem

You are given an integer array nums where each element represents the maximum number of positions you can jump forward from that index. Determine whether you can reach the last index starting from the first index.

Asked At

CompanyDifficulty
OracleMEDIUMView all Oracle questions →

How to Think About It

1.

Think about what each index value means — it tells you how far you can jump from that position.

2.

A brute force approach tries every possible jump from each index using recursion, leading to exponential time.

3.

Dynamic programming can optimize by storing whether each index is reachable, but this still requires O(n) space.

4.

A greedy approach tracks the farthest reachable index as you iterate through the array.

5.

If at any point the current index exceeds the farthest reachable index, return false. Otherwise, return true.

Optimal Approach

Iterate through the array while maintaining the farthest index you can reach. For each position i, update the farthest reachable index as max(farthest, i + nums[i]). If at any point the current index i is beyond the farthest reachable index, you cannot proceed and return false. If you complete the loop, the last index is reachable. This greedy approach runs in O(n) time and O(1) space.

What Trips People Up in Real Interviews

1.

Clarify whether you can jump exactly or at most the given number of positions.

2.

Start with the brute force recursion to show problem understanding before optimizing.

3.

Explain the greedy insight clearly — you only need to track the maximum reachable index.

4.

Mention that this can also be solved with DP but greedy is optimal at O(n) time and O(1) space.

5.

Edge cases: single element array (always true), first element is 0 and array has more than one element (false).

Solution Code

def canJump(nums):
    farthest = 0
    for i in range(len(nums)):
        if i > farthest:
            return False
        farthest = max(farthest, i + nums[i])
    return True

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Jump Game problem?

You are given an integer array nums where each element represents the maximum number of positions you can jump forward from that index. Determine whether you can reach the last index starting from the first index.

How do you solve Jump Game?

The optimal approach is described in detail above, including step-by-step walkthroughs, complexity analysis, and solution code in Python. Scroll up to the "Optimal Approach" section.

What companies ask Jump Game?

Jump Game is asked at Oracle. It is a medium difficulty problem.

What are common mistakes on Jump Game?
  • Clarify whether you can jump exactly or at most the given number of positions.
  • Start with the brute force recursion to show problem understanding before optimizing.
  • Explain the greedy insight clearly — you only need to track the maximum reachable index.
  • Mention that this can also be solved with DP but greedy is optimal at O(n) time and O(1) space.
  • Edge cases: single element array (always true), first element is 0 and array has more than one element (false).