Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Range Selection A set of n integer ranges ( both ends inclusive ) of d length each is given. The starting point of these ranges
Range Selection
A set of integer ranges both ends inclusive of length each
is given. The starting point of these ranges is given in an array
starts. So the range starting with zero index consists of
integers from starts to starts One integer each is to be
chosen from all of the ranges, subject to the condition that the
difference between any pair of chosen integers is at least dist.
Given the starting points of the ranges, in an array starts, and
the length of each range, the task is to determine the
maximum possible value of dist such that it is possible to
choose an integer from each of the ranges satisfying the above
condition.
Example
Suppose and starts
The given ranges are
One integer each has to be chosen from the given ranges such
that the difference between any pair of chosen integers is at
least dist. The aim is to maximize such an integer dist.
It is optimal to choose dist
The integer can be chosen from the range based
indexing
The integer can be chosen from the range
The integer can be chosen from the range
The difference between any pair of chosen integers is at least
So is the maximum possible value of dist.
least dist. The aim is to maximize such an integer dist.
It is optimal to choose dist
The integer can be chosen from the range based
indexing
The integer can be chosen from the range
The integer can be chosen from the range
The difference between any pair of chosen integers is at least
So is the maximum possible value of dist.
Function Description
Complete the function getMaxDist in the editor below.
getMaxDist has the following parameters:
long startsn: the starting points of all the ranges
long : the length of each range
Returns
long int: the maximum possible value of dist such that it is
possible to choose an integer from each of the given ranges
satisfying the given condition.
Constraints
starts
Input Format For Custom Testing
solve it in c
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