Zero To DSAZero To DSA
Privacy Policy
Non-Overlapping IntervalsBest Time to Buy and Sell Stock II

Jump Game

medium
Time: O(n)
Space: O(1)

You are given an integer array nums where each element represents your maximum jump length from that position. Return true if you can reach the last index.

Constraints

  • 1 <= nums.length <= 10⁴

Examples

Input: nums = [2,3,1,1,4]
Output: true
Jump 1 step from 0 to 1, then 3 steps to the end.
Input: nums = [3,2,1,0,4]
Output: false
You get stuck at index 3.