human
Minimum increments to make all array elements equal with sum same as the given array after exactly one removal | Function to check if an array of equal elements with sum equal to the given array can be obtained or not.
Base case.
Stores sum of array elements.
Stores second largest array element.
Stores the largest array element.
Traverse the array.
Update secMax.
Update Max.
Update secMax.
Update totalSum.
If totalSum is less than secMax * ( N - 1 ) ).
If totalSum is not divisible by ( N - 1 ).
Driver Code"
Solution in Python:
assistant
#Here is code to minimum increments to make all array elements equal with sum same as the given array after exactly one removal and the other steps required.
 def CheckAllarrayEqual ( arr , N ) :
	if ( N == 1 ) :
		return True
	totalSum = arr [ 0 ]
	secMax = - 10 ** 19
	Max = arr [ 0 ]
	for i in range ( 1 , N ) :
		if ( arr [ i ] >= Max ) :
			secMax = Max
			Max = arr [ i ]
		elif ( arr [ i ] > secMax ) :
			secMax = arr [ i ]
		totalSum += arr [ i ]
	if ( ( secMax * ( N - 1 ) ) > totalSum ) :
		return False
	if ( totalSum % ( N - 1 ) ) :
		return False
	return True
if __name__ == ' _ _ main _ _ ' :
	arr = [ 6 , 2 , 2 , 2 ]
	N = len ( arr )
	if ( CheckAllarrayEqual ( arr , N ) ) :
		print ( " YES " )
	else :
		print ( " NO " )