human
Minimize steps required to make all array elements same by adding 1 , 2 or 5 | Function to calculate the minimum number of steps.
count stores number of operations required to make all elements equal to minimum value.
Remark , the array should remain unchanged for further calculations with different minimum.
Storing the current value of arr [ i ] in val.
Finds how much extra amount is to be removed.
Subtract the maximum number of 5 and stores remaining.
Subtract the maximum number of 2 and stores remaining.
Restores the actual value of arr [ i ].
Return the count.
Function to find the minimum number of steps to make array elements same.
Sort the array in descending order.
Stores the minimum array element.
Stores the operations required to make array elements equal to minimum.
Stores the operations required to make array elements equal to minimum - 1.
Stores the operations required to make array elements equal to minimum - 2.
Return minimum of the three counts.
Driver Code"
How can the above be solved in Python?
 ... Write me a code to minimize steps required to make all array elements same by adding 1 , 2 or 5 and the other steps required?
assistant
#Here is code to minimize steps required to make all array elements same by adding 1 , 2 or 5 and the other steps required.
 def calculate_steps ( arr , n , minimum ) :
	count = 0
	for i in range ( n ) :
		val = arr [ i ]
		if ( arr [ i ] > minimum ) :
			arr [ i ] = arr [ i ] - minimum
			count += arr [ i ] // 5
			arr [ i ] = arr [ i ] % 5
			count += arr [ i ] // 2
			arr [ i ] = arr [ i ] % 2
			if ( arr [ i ] ) :
				count += 1
		arr [ i ] = val
	return count
def solve ( arr , n ) :
	arr = sorted ( arr )
	arr = arr [ : : - 1 ]
	minimum = arr [ n - 1 ]
	count1 = 0
	count2 = 0
	count3 = 0
	count1 = calculate_steps ( arr , n , minimum )
	count2 = calculate_steps ( arr , n , minimum - 1 )
	count3 = calculate_steps ( arr , n , minimum - 2 )
	return min ( count1 , min ( count2 , count3 ) )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 3 , 6 , 6 ]
	N = len ( arr )
	print ( solve ( arr , N ) )