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 II problem solution

YASH PAL, 31 July 202418 January 2026

In this Leetcode Jump Game II problem solution, we have given an array of non-negative integers nums, and you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. You can assume that you can always reach the last index.

Leetcode Jump Game II problem solution

Leetcode Jump Game II problem solution in Python.

class Solution(object):
def jump(self, nums):
    res = 0
    edge = 0
    maxEdge = 0
    for i in range(len(nums)):
        if i > edge:
            edge = maxEdge
            res += 1
        maxEdge = max(maxEdge,i+nums[i])
    return res

Jump Game II problem solution in Java.

class Solution {
    public int jump(int[] nums) {
         int ladder = 0;
         int stair = 1;
         int jump = 0;
 
         for (int level = 0; level < nums.length; level++) {
             if (level == nums.length - 1) {
                 return jump;
             }
             if (nums[level] + level >= ladder)
                 ladder = nums[level] + level;
 
             stair--;
 
             if (stair == 0) {
                 jump++;
                 stair = ladder - level;
                 if (stair == 0)
                     return -1;
             }
         }
         return jump;
    }
}

Problem solution in C++.

class Solution {
public:
    int jump(vector<int>& nums) {
        int jumps = 0 , limit = 0 , next_limit = 0;
        for(int i = 0;i < nums.size()-1;i++){
            next_limit = max(next_limit,i+nums[i]);
            if(i == limit){
                jumps++;
                limit = next_limit;
            }
        }
        return jumps;
    }
};

Problem solution in C.

int jump(int* n, int ns){
    if(ns <= 1) return 0;
    int r = n[0];
    if(r >= ns - 1) return 1;
    int max = r + n[r];
    int maxid = r;
    for(int i = 1; i <= r; i++)
        if(n[i] + i > max)
            max = n[i] + i, maxid = i;
    return jump(&n[maxid], ns - maxid) + 1;
}

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