Jump Game — Can You Reach the End?

M · mediumP · Verified PYQAmbiguous I/Oarraysdp

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.

Input
2,3,1,1,4
Output
true
The I/O format for this question is intentionally ambiguous — TCS NQT sometimes omits full specs. Practice parsing.
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.
← Inventory Frequency CounterLargest of Three Numbers →
Report an issue with this question