text: Minimize increments required to make count of even and odd array elements equal | C # program to implement the above approach ; Function to find min operations to make even and odd count equal ; Odd size will never make odd and even counts equal ; Stores the count of even numbers in the array arr [ ] ; Stores count of odd numbers in the array arr [ ] ; Traverse the array arr [ ] ; If arr [ i ] is an even number ; Update cntEven ; Odd numbers in arr [ ] ; Return absolute difference divided by 2 ; Driver Code ; Function call
code: using System ; class GFG { static int minimumIncrement ( int [ ] arr , int N ) { if ( N % 2 != 0 ) { Console . WriteLine ( " - 1" ) ; Environment . Exit ( 0 ) ; } int cntEven = 0 ; int cntOdd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { cntEven += 1 ; } } cntOdd = N - cntEven ; return Math . Abs ( cntEven - cntOdd ) / 2 ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 4 , 9 } ; int N = arr . Length ; Console . WriteLine ( minimumIncrement ( arr , N ) ) ; } }