human
Reduce given array by replacing subarrays with values less than K with their sum | Function to replace all the subarray having values < K with their sum.
Stores the sum of subarray having elements less than K.
Stores the updated array.
Traverse the array.
Update the sum.
Otherwise , update the vector.
Print the result.
Driver Code"
Solution in Python:
 ... Write me a code to reduce given array by replacing subarrays with values less than K with their sum and the other steps required?
assistant
#Here is code to reduce given array by replacing subarrays with values less than K with their sum and the other steps required.
 def updateArray ( arr , K ) :
	sum = 0
	res = [ ]
	for i in range ( 0 , int ( len ( arr ) ) ) :
		if ( arr [ i ] < K ) :
			sum += arr [ i ]
		else :
			if ( sum != 0 ) :
				res . append ( sum )
			sum = 0
			res . append ( arr [ i ] )
	if ( sum != 0 ) :
		res . append ( sum )
	for it in res :
		print ( it , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
	arr = [ 200 , 6 , 36 , 612 , 121 , 66 , 63 , 39 , 668 , 108 ]
	K = 100
	updateArray ( arr , K )