Jump Game
Updated
Problem statement
An integer array nums holds n values, and you begin on index 0. Each value nums[i] caps how far a single jump from index i can go: the jump may land on any index j with i < j <= i + nums[i], provided j is still a position in the array. So a 0 at index i leaves you no move from there.
Return true when some sequence of jumps lands on the last index (index n - 1), and false otherwise.
Function
canJump(nums: int[]) → booleanExamples
Example 1
nums = [1,2,0,1,3]return = trueJump 1 step from index 0 to index 1, then 2 steps to index 3, then 1 step to index 4. Since n is 5, index 4 is the last index.
Example 2
nums = [2,1,0,3]return = falseIndex 0 allows a jump to index 1 or 2, and index 1 allows a jump to index 2 and no farther. The value at index 2 is 0, so every path stops there and index 3, the last index, stays out of reach.
Example 3
nums = [0]return = trueWith a single value, index 0 is also the last index, so you are done before making any jump; the 0 stored there never matters.
Constraints
1 <= nums.length <= 1040 <= nums[i] <= 105
More Zillow Phone Screen questions
- Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
- Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
- Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
- Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
- Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
- Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
- Employee Free TimePHONE SCREEN · Seen Oct 2022
- First Unique Character in a StringPHONE SCREEN · Seen Oct 2022
- K-th Smallest Number in a StreamPHONE SCREEN · Seen Oct 2022
Similar questions at other companies
- Jump GamePaytm · PHONE SCREENPaytm interview questions
- 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