Jump Game — Can You Reach the End?
M · mediumP · Verified PYQAmbiguous I/Oarraysdp
Problem
Given an array where each element represents the maximum number of steps you can jump forward from that position, determine if you can reach the last index starting from index 0. Print “true” if reachable, “false” otherwise.
Example
Input
2,3,1,1,4
Output
true
Track maxReach. For each index i <= maxReach: maxReach = max(maxReach, i+nums[i]). If maxReach >= n-1, return true.
From index 0 jump 2 → index 2. From index 2 jump 1 → index 3. From index 3 jump 1 → last index.