Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code javascript: Given the distinct positions of holes, find the shortest length of two identical boards that can cover all the holes. Task description There
code javascript:
Given the distinct positions of holes, find the shortest length of two identical boards that can cover all the holes.
Task description
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 Kth hole is AK 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 XL inclusive The position of every hole is unique.
Write a function:
function solutionA;
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 holes.
Examples:
Given A your function should return The first board would cover the holes in positions and and the second board the hole at position
Given A your function should return The first board covers the holes at positions and and the second one the holes in positions and
Given A your function should return The first board would cover the holes in positions between and and the second the positions between and
Given A your function should return
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
each element of array A is an integer within the range ;
the elements of A are all distinct.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started