human
Write me a code to elements to be added so that all elements of a range are present in array and the other steps required given the following:
Elements to be added so that all elements of a range are present in array | Function to count numbers to be added.
Sort the array.
Check if elements are consecutive or not . If not , update count.
Drivers code"
Solution in Python:
assistant
#Here is code to elements to be added so that all elements of a range are present in array and the other steps required.
 def countNum ( arr , n ) :
	count = 0
	arr . sort ( )
	for i in range ( 0 , n - 1 ) :
		if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :
			count += arr [ i + 1 ] - arr [ i ] - 1 ;
	return count
arr = [ 3 , 5 , 8 , 6 ]
n = len ( arr )
print ( countNum ( arr , n ) )