Jump Game
Updated
Problem statement
You are given an integer array nums. You start at index 0. From index i, you can jump forward to any index from i + 1 to i + nums[i]. You do not have to use the full jump length. A value of 0 means you cannot move on from that index.
Return true if you can reach the last index, or false otherwise.
Function
canJump(nums: int[]) → booleanExamples
Example 1
nums = [2,0,2,0,1]return = trueFrom index 0, jump 2 to index 2. From index 2, jump 2 to index 4, which is the last index.
Example 2
nums = [1,2,0,0,3]return = falseFrom index 0 you can only reach index 1. From index 1 you can reach index 2 or 3, and both hold 0. So you get stuck and never reach index 4.
Example 3
nums = [0]return = trueThe array has one element, so you already stand on the last index.
Constraints
1 <= nums.length <= 10^40 <= nums[i] <= 10^5
More Paytm interview questions
- Nth Highest SalaryPHONE SCREEN · Seen Nov 2026
- Second Highest SalaryPHONE SCREEN · Seen Nov 2026
- LRU Cache with Expiring EntriesPHONE SCREEN · Seen Sep 2026
- Detect a Linked-List CycleONSITE INTERVIEW · Seen Sep 2026
- Find First and Last Position in Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
- Minimum Coins for a TargetONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
- Jump Game IINavi · PHONE SCREEN
- Best Stock Profit With a Sell FeeKaseya · PHONE SCREEN
- Fewest Jumps to the End or StuckAdobe · PHONE SCREENAdobe interview questions
- Return a Minimum-Coin Change BreakdownDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Most Relevant Text SpanHebbia · PHONE SCREEN
- Fewest Jumps to the End of an ArrayRippling · PHONE SCREENRippling interview questions
- Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
- Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Best Time to Buy and Sell StockJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions