Make array elements equal with minimum cost | Java implementation to make array elements equal with minimum cost ; Function to find the minimum cost required to make array elements equal ; Loop to find the count of odd elements ; Driver Code
class GFG { static void makearrayequal ( int arr [ ] , int n ) { int x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x += ( arr [ i ] & 1 ) ; } System . out . println ( Math . min ( x , n - x ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 3 , 2 , 1 } ; int n = arr . length ; makearrayequal ( arr , n ) ; } }