Minimize increments required to make differences between all pairs of array elements even | Java program for the above approach ; Function to find the minimum increments required to difference between all pairs of array elements even ; Store the count of odd and even numbers ; Traverse the array ; Increment evenCnt by 1 ; Increment oddCnt by 1 ; Print the minimum of oddCnt and eveCnt ; Driver code
public class GFG { static void minimumOperations ( int [ ] arr , int N ) { int oddCnt = 0 , evenCnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { evenCnt ++ ; } else { oddCnt ++ ; } } System . out . print ( Math . min ( oddCnt , evenCnt ) ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 4 , 1 , 2 } ; int N = arr . length ; minimumOperations ( arr , N ) ; } }