Leetcode – 55. Jump Game

so this is a greedy approach

our goal is to reach the last index , so we try to reach to index 0 and if we are able to make it , then we return True otherwise False

coming from back makes it to become a sub problem

Example – [2,3,1,1,4]

the …


This content originally appeared on DEV Community and was authored by Rakesh Reddy Peddamallu

so this is a greedy approach

our goal is to reach the last index , so we try to reach to index 0 and if we are able to make it , then we return True otherwise False

coming from back makes it to become a sub problem

Example - [2,3,1,1,4]

Image description

the above can converted to
Image description

since anyways we can jump from 1 to 4

this again gets converted to
Image description

this again gets converted to

Image description

this again gets converted to

Image description

So now my goal is at index 0 which means , u can jump to last index if u begin from 0 index too

CODE

/**
 * @param {number[]} nums
 * @return {boolean}
 */
var canJump = function(nums) {


    let goal = nums.length-1 ; 


    for(let i = nums.length-1 ;i>=0 ;i--){

       if(i+nums[i] >= goal){

            goal = i;
       }
    }

    return goal==0
};


This content originally appeared on DEV Community and was authored by Rakesh Reddy Peddamallu


Print Share Comment Cite Upload Translate Updates
APA

Rakesh Reddy Peddamallu | Sciencx (2025-01-25T16:48:47+00:00) Leetcode – 55. Jump Game. Retrieved from https://www.scien.cx/2025/01/25/leetcode-55-jump-game/

MLA
" » Leetcode – 55. Jump Game." Rakesh Reddy Peddamallu | Sciencx - Saturday January 25, 2025, https://www.scien.cx/2025/01/25/leetcode-55-jump-game/
HARVARD
Rakesh Reddy Peddamallu | Sciencx Saturday January 25, 2025 » Leetcode – 55. Jump Game., viewed ,<https://www.scien.cx/2025/01/25/leetcode-55-jump-game/>
VANCOUVER
Rakesh Reddy Peddamallu | Sciencx - » Leetcode – 55. Jump Game. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/25/leetcode-55-jump-game/
CHICAGO
" » Leetcode – 55. Jump Game." Rakesh Reddy Peddamallu | Sciencx - Accessed . https://www.scien.cx/2025/01/25/leetcode-55-jump-game/
IEEE
" » Leetcode – 55. Jump Game." Rakesh Reddy Peddamallu | Sciencx [Online]. Available: https://www.scien.cx/2025/01/25/leetcode-55-jump-game/. [Accessed: ]
rf:citation
» Leetcode – 55. Jump Game | Rakesh Reddy Peddamallu | Sciencx | https://www.scien.cx/2025/01/25/leetcode-55-jump-game/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.