DEV Community

Rakesh Reddy Peddamallu
Rakesh Reddy Peddamallu

Posted on

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]

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
};
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more