Maximize the count of adjacent element pairs with even sum by rearranging the Array | C # program for the above approach ; Function to find maximum count pair of adjacent elements with even sum ; Stores count of odd numbers ; Stores count of even numbers ; Traverse the array arr [ ] ; If arr [ i ] % 2 is 1 ; Else ; If odd and even both are greater than 0 ; Otherwise ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maximumCount ( int [ ] arr , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 != 0 ) odd ++ ; else even ++ ; } if ( odd != 0 && even != 0 ) return N - 2 ; else return N - 1 ; } public static void Main ( ) { int [ ] arr = { 9 , 13 , 15 , 3 , 16 , 9 , 13 , 18 } ; int N = arr . Length ; Console . Write ( maximumCount ( arr , N ) ) ; } }