logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
logoNEURAL COOK

A posts created with Next.js and Tailwind.css

Explore

  • All posts
  • Notes
  • Snippets
  • Tags
  • RSS feed

Connect

instagramtwitterfacebookyoutubelinkedinmailgithub

© 2026 VIKI. All rights reserved.

Built with
Contents
Table Of Contents
25. Reverse Nodes in k-Group26. Remove Duplicates from Sorted Array27. Remove Element42. Trapping Rain Water51. N-Queens55. Jump Game80. Remove Duplicates from Sorted Array II88. Merge Sorted Array121. Best Time to Buy and Sell Stock122. Best Time to Buy and Sell Stock II189. Rotate Array274. H-Index
Code Scratch/leetcode/hard

55. Jump Game

1 min read
On this pageIntuition
IntuitionApproachComplexityCode

# Intuition

  • We can use the back-tracking approach , with memorisation to avoid duplicate effort

# Approach

  • When at iii try taking all possible jumps and return if any one works.

# Complexity

  • Time complexity : O()\text{O}()O()
  • Space complexity : O()\text{O}()O()

# Code

class Solution {
    Set < Integer > failing = new HashSet < > ();
 
    public boolean jumping(int[] nums, int i) {
        if (i >= nums.length - 1)
            return true;
 
        if (nums[i] == 0)
            return false;
 
		for (int j = Math.min(nums[i],nums.length - i) ; j > 0; --j) {
            if (failing.contains(i + j))
                continue;
 
            if (jumping(nums, i + j))
                return true;
 
            failing.add(i + j);
        }
 
        return false;
    }
 
    public boolean canJump(int[] nums) {
        return jumping(nums, 0);
    }
}
←Previous51. N-QueensNext→80. Remove Duplicates from Sorted Array II

On this page

IntuitionApproachComplexityCode