All problemsBack
Jump Game
mediumYou are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last index, or false otherwise.
Test Cases
Copy an input into themain harness and Run to verifyInput
nums = [2,3,1,1,4]Expected Output
trueExplanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
Input
nums = [3,2,1,0,4]Expected Output
falseExplanation: You always arrive at index 3, whose maximum jump length is 0.
Constraints
- 1 <= nums.length <= 10^4
- 0 <= nums[i] <= 10^5
Hints
Hint 1 — click to reveal
You do not need to know *how* you get somewhere — only how far you can possibly reach.
Hint 2 — click to reveal
Track the furthest reachable index as you scan; if it ever falls behind you, you are stuck.
Java Compiler
Powered by OneCompiler. Starter code loads automatically — edit and hit Run.