We are given coordinates of obstacles on a straight line. We start jumping from point 0, we need to reach end avoiding all obstacles. Length of every jump has to be same (For example, if we jump from 0 to 4, then we must make next jump from 4 to 8). We need to find the minimum length of jump so that we can reach end and we avoid all obstacles.
Input : obs = [5, 3, 6, 7, 9] Output : 4 Obstacles are at points 3, 5, 6, 7 and 9 We jump from 0 to 4, then 4 to 8, then 4 to 12. This is how we reach end with jumps of length 4. If we try lower jump lengths, we cannot avoid all obstacles. Input : obs = [5, 8, 9, 13, 14] Output : 6
We insert locations of all obstacles in a hash table. We also find maximum value of obstacle. Then we try all possible jump sizes from 1 to maximum. If any jump size leads to a obstacle, we do not consider that jump.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find the minimum of maximum length of a jump required to reach the last island in exactly k jumps
- Count minimum factor jumps required to reach the end of an Array
- Minimum number of Circular obstacles required to obstruct the path in a Grid
- Check if it is possible to reach a number by making jumps of two given length
- Find minimum length sub-array which has given sub-sequence in it
- Minimum length subarray of 1s in a Binary Array
- Minimum length of the reduced Array formed using given operations
- Minimum number of Fibonacci jumps to reach end
- Minimum number of jumps to reach end | Set 2 (O(n) solution)
- Find the Minimum length Unsorted Subarray, sorting which makes the complete array sorted
- Number of K length subsequences with minimum sum
- Minimum length substring with exactly K distinct characters
- Minimum length subarray containing all unique elements after Q operations
- Subarray with difference between maximum and minimum element greater than or equal to its length
- Maximum and minimum of an array using minimum number of comparisons
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.