Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Leetcode Jump Game problem solution

YASH PAL, 31 July 202418 January 2026

In this Leetcode Jump Game problem solution, we have 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.

leetcode jump game problem solution

Leetcode Jump Game problem solution in Python.

class Solution:
    def canJump(self, nums: List[int]) -> bool:
        l = 0
        r = nums[l]
        x = len(nums)-1
        while(r<x):
            if l == r: return False
            l, r = r, max(i+nums[i] for i in range(l, r+1))
            
        return True

Jump Game problem solution in Java.

public class Solution {
    public boolean canJump(int[] nums) {
        int i = 0;
        while(i<nums.length)
        {
            if(nums[i] == 0&&i!=nums.length-1)
            {
                return false;
            }
            int max = Integer.MIN_VALUE;
            int next = i+1;
            for(int j = 1;j<nums[i]+1;j++)
            {
                if(i+j>nums.length-1)
                {
                    return true;
                }
                if(nums[i+j]+j-1>max)
                {
                    max = nums[i+j]+j-1;
                    next = i+j;
                }
            }
            i = next;
        }
        return true;
    }
}

Problem solution in C++.

class Solution {
public:
    bool canJump(vector<int>& nums) {
        if(nums.size()==1) return true  ; 
        if(!nums.size()) return false   ;
        int maxx = 0    ; 
        bool ans = true ;
        for(int i = 0 ; i < nums.size() ; i ++ )
        {
            if( nums[i] ) maxx = max( maxx , i + nums[i] ) ;
            else 
            {
                if( maxx <= i && i != nums.size() - 1 ) {ans = false ; break ; }
            }
        }
        return ans ;
    }
};

Problem solution in C.

bool canJump(int* nums, int numsSize) {

    int step=nums[0],i=0;
    
    while(step>0 && i<numsSize)
    {
        i++;
        step--;
        step = step>nums[i]? step:nums[i];
    }
    
    if(i<numsSize-1)
        return false;
    return true;
}

coding problems solutions Leetcode Problems Solutions Leetcode

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes