human
Compress the array into Ranges | Function to compress the array ranges.
start iteration from the ith array element.
loop until arr [ i + 1 ] == arr [ i ] and increment j.
if the program do not enter into the above while loop this means that ( i + 1 ) th element is not consecutive to i th element.
increment i for next iteration.
print the consecutive range found.
move i jump directly to j + 1.
Driver code"
Solution in Python:
assistant
#Here is code to compress the array into Ranges and the other steps required.
 def compressArr ( arr , n ) :
	i = 0 ;
	j = 0 ;
	arr . sort ( ) ;
	while ( i < n ) :
		j = i ;
		while ( ( j + 1 < n ) and ( arr [ j + 1 ] == arr [ j ] + 1 ) ) :
			j += 1 ;
		if ( i == j ) :
			print ( arr [ i ] , end = " ▁ " ) ;
			i += 1 ;
		else :
			print ( arr [ i ] , " - " , arr [ j ] , end = " ▁ " ) ;
			i = j + 1 ;
n = 7 ;
arr = [ 1 , 3 , 4 , 5 , 6 , 9 , 10 ] ;
compressArr ( arr , n ) ;