Fewest Jumps to the End of an Array
Updated
Problem statement
You stand at index 0 of an integer array nums. nums[i] is the longest jump you can make from index i: from i you may jump to any index from i + 1 up to i + nums[i], as long as it is inside the array. A value of 0 means you cannot move from that index.
Return the fewest jumps needed to land on the last index, nums.length - 1. If the last index cannot be reached, return -1.
Function
jump(nums: int[]) → intExamples
Example 1
nums = [3,1,4,1,1,2,1,1]return = 3From index 0 you can reach indices 1 to 3. The best of those is index 2, which reaches up to index 6. From index 6 one more jump reaches index 7. That is 3 jumps (0 to 2 to 6 to 7). Two jumps are not enough: from indices 1, 2 and 3 the farthest you can get is index 6.
Example 2
nums = [2,1,0,3]return = -1From index 0 you can reach index 1 or 2. Index 1 only reaches index 2, and index 2 holds 0, so you are stuck. Index 3 cannot be reached: return -1.
Example 3
nums = [0]return = 0You already stand on the last index, so you need 0 jumps.
Constraints
1 <= nums.length <= 100000 <= nums[i] <= 1000
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
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
- 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
Interview reports that mention this question
Rippling interview experiences
- Rippling No-Level Older Reports: 31 Experiences (Part 6 of 6)
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling No-Level Design, Screens: 30 Experiences (Part 2 of 6)