Asked inDE Shaw,Associate Developer Intern

Jump Game Problem Statement

In this problem, you are given an array ARR consisting of N integers. Your task is to determine the minimum number of jumps required to reach the last index of the array N - 1. At any given index i, you can jump to any index between i + 1 and i + ARR[i] inclusive. The element at index i specifies the maximum distance you can jump from that index.

Input:

The input begins with an integer, T, representing the number of test cases. For each test case, the first line contains an integer N, representing the number of elements in ARR. The following line consists of N space-separated integers, which are the elements of ARR.

The first line of input contains an integer ‘T’
The first line of each test case contains an integer ‘N’
The second line of each test case contains ‘N’ space-separated integers

Output:

For each test case, output a single integer, which is the minimum number of jumps required to reach the last index. Each test case result should be printed on a new line.

For each test case, print a single line containing a single integer

Example:

Consider the following example:

Input:
T = 1
N = 6
ARR = [2, 3, 1, 1, 4, 2]

Output:
2

Explanation: Start from index 0, jump to index 1, and then directly to index 5.

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 10^4
  • 1 <= ARR[i] <= 10^4
  • Assume that you can always reach the last index.
  • Time limit: 1 sec.
Note:

All inputs are based on 0-based indexing.

Be the first one to answer
Add answer anonymously...
DE Shaw Associate Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter