Minimum Number of Jumps Problem

Given an array ARR of N integers, determine the minimum number of jumps required to reach the last index of the array (i.e., N - 1). From any index i, you can jump to an index i + k where 1 ≤ k ≤ ARR[i]—in other words, the current array element indicates the maximum distance you can jump from that position.

Input:

The first line contains an integer ‘T’ representing the number of test cases. 
The first line of each test case consists of an integer ‘N’, the number of elements in the array.
The second line contains ‘N’ space-separated integers, representing the elements of the array.

Output:

For each test case, output the minimum number of jumps needed to reach the last index on a new line.

Example:

If the input is:

Input:
2
5
2 3 1 1 4
6
2 2 1 2 1 1
Output:
2
3
Explanation:

In the first test case, the jumps are as follows: from index 0 to 1, and then from index 1 to the last index.
In the second test case, the jumps are: from index 0 to 1, from 1 to 3, and finally, from 3 to the last index.

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 104
  • 1 ≤ ARR[i] ≤ 104 where ARR[i] is the i-th element of the array.
  • Time limit: 1 second
Note:

You only need to implement the function to determine the minimum jumps; the input and output processes are handled for you.

AnswerBot
4mo

The problem involves finding the minimum number of jumps required to reach the last index of an array, where each element indicates the maximum distance that can be jumped from that position.

  • Use a gre...read more

Help your peers!
Select
Add answer anonymously...

Cadence Design Systems SDE-2 interview questions & answers

A SDE-2 was asked 3mo agoQ. Design a data structure that supports the following two operations: void addNum(...read more
A SDE-2 was asked 3mo agoQ. How would you sort an array based on a user-defined order?
A SDE-2 was asked 3mo agoQ. What is a copy constructor?

Popular interview questions of SDE-2

A SDE-2 was asked 2mo agoQ1. Design a data structure that supports the following two operations: void addNum(...read more
A SDE-2 was asked 2mo agoQ2. How would you sort an array based on a user-defined order?
A SDE-2 was asked 2mo agoQ3. What is a copy constructor?
Cadence Design Systems SDE-2 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