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
4mo

Find the minimum number of trampoline jumps Bob needs to make to reach the final shop, or return -1 if it's impossible.

  • Use Breadth First Search (BFS) algorithm to find the minimum number of jumps requ...read more

Help your peers!
Select
Add answer anonymously...

MakeMyTrip Software Developer interview questions & answers

A Software Developer was asked 5mo agoQ. Given an integer array of size n, find the maximum circular subarray sum. A circ...read more
A Software Developer was asked 5mo agoQ. Design a minimum stack that supports the following operations: push, pop, top, a...read more
A Software Developer was asked Q. Given a linked list, determine if it is a palindrome.

Popular interview questions of Software Developer

A Software Developer was asked 5mo agoQ1. Given an integer array of size n, find the maximum circular subarray sum. A circ...read more
A Software Developer was asked 5mo agoQ2. Design a minimum stack that supports the following operations: push, pop, top, a...read more
A Software Developer was asked Q3. Given a linked list, determine if it is a palindrome.
MakeMyTrip Software 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