In this java tutorial, we will learn to choose the minimum step size to travel over the positive integer number line such that we don't encounter a single obstacle
An array of positive integers, which indicates obstacles over the number line.
Let an array be a such that 0<a[i]<Z+ , where Z+ is any positive integer
In the above representation the symbol '@' indicates the presence of an obstacle.
That number is chosen as a step for which the modulo with every single element of the array is not equal to zero.
For the above example, the minimum step size to avoid all the obstacles is 8.
(by means of jumping over the number line starting from 0 with that step size)
2<= input array.length <=1000
1<= input array[i]<=1000
return the integer with a minimum step size
enter the no of obstacles in an array 7
enter the value of nodes which are assumed as an obstacle on the number line 2 3 5 7 11 12 13
The minimum step size that avoids all the obstacles is 8
Submitted by Matam Deekshith (deekshithmatam)
Download packets of source code on Coders Packet