Shortest Board Length to Cover Holes
There are N holes arranged in a row in the top of an old table. We want to fix the table by covering the holes with two boards. For technical reasons, the boards need to be of the same length.
The position of the K-th hole is A[K]. What is the shortest length of the boards required to cover all the holes? The length of the boards has to be a positive integer. A board of length L, set at position X, covers all the holes located between positions X and X+L (inclusive). The position of every hole is unique.
Complete the func in the editor 👉
which, given an array A of integers of length N, representing the positions of the holes in the table, returns the shortest board length required to cover all the hotels.
1Example 1
2Example 2
3Example 3
4Example 4
Constraints
Limits and guarantees your solution can rely on.
N is an integer within the range [1..100,000]each element of array A is an integer within the range 0..1,000,000,000the elements of A are all distinct