human
Min steps to empty an Array by removing a pair each time with sum at most K | Function to count minimum steps.
Function to sort the array.
Run while loop.
Condition to check whether sum exceed the target or not.
Increment the step by 1.
Return minimum steps.
Given array arr [ ].
Given target value.
Function call"
How can the above be solved in Python?
assistant
#Here is code to min steps to empty an Array by removing a pair each time with sum at most K and the other steps required.
 def countMinSteps ( arr , target , n ) :
	arr . sort ( )
	minimumSteps = 0
	i , j = 0 , n - 1
	while i <= j :
		if arr [ i ] + arr [ j ] <= target :
			i += 1
			j -= 1
		else :
			j -= 1
		minimumSteps += 1
	return minimumSteps
arr = [ 4 , 6 , 2 , 9 , 6 , 5 , 8 , 10 ]
target = 11
size = len ( arr )
print ( countMinSteps ( arr , target , size ) )