Minimum Jumps Problem Statement

Bob and his wife are in the famous 'Arcade' mall in the city of Berland. This mall has a unique way of moving between shops using trampolines. Each shop is laid out in a straight line, and from any shop 'i', you can jump to any shop ranging from 'i' to 'i + Arr[i]', where 'Arr[i]' is a given constant for each shop.

The task is to determine the minimum number of trampoline jumps Bob has to make from shop 0 to reach the final shop (N-1) to reunite with his wife. If Bob cannot reach the last shop, return -1.

Input:

The input begins with a single integer T, representing the number of test cases. 
For each test case, the first line contains a positive integer N, indicating the number of shops.
The second line includes N space-separated integers, representing the array 'Arr' for the shops.

Output:

For each test case, output the minimum number of jumps required to reach the last shop, or -1 if it's impossible.

Example:

Input:
2
5
2 3 1 1 4
5
3 2 1 0 4
Output:
2
-1
Explanation:

For the first test case, starting at shop 0, a jump of 1 goes to shop 1, followed by another jump directly to shop 4, a total of 2 jumps. For the second test case, once reaching shop 3, no more jumps can be made (Arr[3] = 0), so reaching the last shop is impossible.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 5 * 10^4
  • 0 <= Arr[i] <= N
AnswerBot
1y

This question asks for the minimum number of trampoline jumps a person needs to make in order to reach the last shop in a mall.

  • The shops in the mall are laid out in a straight line and each shop has a...read more

Help your peers!
Select
Add answer anonymously...
Zopsmart Technology Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits