human
What is a code to minimum change in given value so that it lies in all given Ranges and the other steps required given the following:
Minimum change in given value so that it lies in all given Ranges | Function to find the minimum difference in the number D such that D is inside of every range.
Loop to find the common range out of the given array of ranges ..
Storing the start and end index.
Sorting the range.
Finding the maximum starting value of common segment.
Finding the minimum ending value of common segment.
If there is no common segment.
If the given number is between the computed common range ..
Finding the minimum distance.
Driver Code.
Given array of ranges"
Solution in Python:
assistant
#Here is code to minimum change in given value so that it lies in all given Ranges and the other steps required.
 def findMinimumOperation ( n , d , arrays ) :
	cnt = 0
	first = - 10 ** 9
	end = 10 ** 9
	while ( n ) :
		arr = [ arrays [ cnt ] [ 0 ] , arrays [ cnt ] [ 1 ] ]
		arr = sorted ( arr )
		first = max ( first , arr [ 0 ] )
		end = min ( end , arr [ 1 ] )
		cnt += 1
		n -= 1
	if ( first > end ) :
		print ( " - 1" , end = " " )
	else :
		if ( d >= first and d <= end ) :
			print ( "0" , end = " " )
		else :
			print ( min ( abs ( first - d ) , abs ( d - end ) ) , end = " " )
if __name__ == ' _ _ main _ _ ' :
	n = 3
	d = 3
	arrays = [ [ 0 , 7 ] , [ 2 , 14 ] , [ 4 , 6 ] ]
	findMinimumOperation ( n , d , arrays )