human
Difference between sum of K maximum even and odd array elements | Function to find the absolute difference between sum of first K maximum even and odd numbers.
Stores index from where odd number starts.
Segregate even and odd number.
If current element is even.
Sort in decreasing order even part.
Sort in decreasing order odd part.
Calculate sum of k maximum even number.
Calculate sum of k maximum odd number.
Print the absolute difference.
Given array [ ] arr.
Size of array.
Function Call"
Solution in Python:
 Give me a code to difference between sum of K maximum even and odd array elements and the other steps required?
assistant
#Here is code to difference between sum of K maximum even and odd array elements and the other steps required.
 def evenOddDiff ( a , n , k ) :
	j = - 1
	even = [ ]
	odd = [ ]
	for i in range ( n ) :
		if ( a [ i ] % 2 == 0 ) :
			even . append ( a [ i ] )
		else :
			odd . append ( a [ i ] )
	j += 1
	even . sort ( )
	even . reverse ( )
	odd . sort ( )
	odd . reverse ( )
	evenSum , oddSum = 0 , 0
	for i in range ( k ) :
		evenSum += even [ i ]
	for i in range ( k ) :
		oddSum += odd [ i ]
	print ( abs ( evenSum - oddSum ) )
arr = [ 1 , 8 , 3 , 4 , 5 ]
N = len ( arr )
K = 2
evenOddDiff ( arr , N , K )