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.
A = [11, 20, 15] return = 4
A = [15, 20, 9, 11] return = 5
A = [0, 44, 32, 30, 42, 18, 34, 16, 35] return = 18
A = [9] return = 1
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- Neural Network Subnetwork StrengthOA · Seen Jun 2026
- XOR MultiplicationOA · Seen Jun 2026
- Maximum Escape Game ScoreOA · Seen Jun 2026
- Minimum Cost K-Capable ModelsOA · Seen Jun 2026
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
public int coverHotels(int[] A) {
// write your code here
}