human
Delete odd and even numbers at alternate step such that sum of remaining elements is minimized | Function to find the minimized sum.
If more odd elements.
Sort the elements.
Left - over elements.
Find the sum of leftover elements.
Return the sum.
If more even elements.
Sort the elements.
Left - over elements.
Find the sum of leftover elements.
Return the sum.
If same elements.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to delete odd and even numbers at alternate step such that sum of remaining elements is minimized and the other steps required.
 def MinimizeleftOverSum ( a , n ) :
	v1 , v2 = [ ] , [ ] ;
	for i in range ( n ) :
		if ( a [ i ] % 2 ) :
			v1 . append ( a [ i ] ) ;
		else :
			v2 . append ( a [ i ] ) ;
	if ( len ( v1 ) > len ( v2 ) ) :
		v1 . sort ( ) ;
		v2 . sort ( ) ;
		x = len ( v1 ) - len ( v2 ) - 1 ;
		sum = 0 ;
		i = 0 ;
		while ( i < x ) :
			sum += v1 [ i ] ;
			i += 1
		return sum ;
	elif ( len ( v2 ) > len ( v1 ) ) :
		v1 . sort ( ) ;
		v2 . sort ( ) ;
		x = len ( v2 ) - len ( v1 ) - 1 ;
		sum = 0 ;
		i = 0 ;
		while ( i < x ) :
			sum += v2 [ i ] ;
			i += 1
		return sum ;
	else :
		return 0 ;
if __name__ == " _ _ main _ _ " :
	a = [ 2 , 2 , 2 , 2 ] ;
	n = len ( a ) ;
	print ( MinimizeleftOverSum ( a , n ) ) ;