Avoiding Traps Problem Statement

Given an array of obstacles' coordinates, determine the minimal jump length to reach beyond all obstacles starting from coordinate 0 while avoiding landing on any obstacle.

Input:

The first line gives an integer ‘T’, the number of test cases. Each test case is presented over two lines:

  1. An integer ‘N’ indicating the number of obstacles.
  2. An array named 'OBSTACLES', containing 'N' integers representing the coordinates of obstacles on the line.

Output:

For each test case, output an integer representing the minimum jump length needed to bypass all obstacles.

Example:

Input:
2
3
1 4 9
4
2 3 6 8
Output:
5
7

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 1000
  • 1 <= OBSTACLES[i] <= 10^6
Note:
  • The endpoint to aim for is any point beyond the maximum obstacle coordinate.
  • The jump length must consistently avoid all listed obstacle points.
  • Obstacles may be unsorted initially.
  • The final jump is permitted to overshoot the line's end point.
Be the first one to answer
Add answer anonymously...
Deutsche Bank Software Developer 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