human
Sort elements of the array that occurs in between multiples of K | Utility function to print the contents of an array.
Function to sort elements in between multiples of k.
To store the index of previous multiple of k.
If it is not the first multiple of k.
Sort the elements in between the previous and the current multiple of k.
Update previous to be current.
Print the updated array.
Driver code"
Solution in Python:
assistant
#Here is code to sort elements of the array that occurs in between multiples of K and the other steps required.
 def printArr ( arr , n ) :
	for i in range ( n ) :
		print ( arr [ i ] , end = " ▁ " ) ;
def sortArr ( arr , n , k ) :
	prev = - 1 ;
	for i in range ( n ) :
		if ( arr [ i ] % k == 0 ) :
			if ( prev != - 1 ) :
				temp = arr [ prev + 1 : i ] ;
				temp . sort ( ) ;
				arr = arr [ : prev + 1 ] + temp + arr [ i : ] ;
			prev = i ;
	printArr ( arr , n ) ;
if __name__ == " _ _ main _ _ " :
	arr = [ 2 , 1 , 13 , 3 , 7 , 8 , 21 , 13 , 12 ] ;
	n = len ( arr ) ;
	k = 2 ;
	sortArr ( arr , n , k ) ;