
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
whereARR[i]
is thei-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.


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

Top Cadence Design Systems SDE-2 interview questions & answers
Popular interview questions of SDE-2
Reviews
Interviews
Salaries
Users/Month