Minimum cost required to move all elements to the same position | Function to find the minimum cost required to place all elements in the same position ; Stores the count of even and odd elements ; Traverse the array arr [ ] ; Count even elements ; Count odd elements ; Print the minimum count ; Given array ; Function Call
function minCost ( arr ) { let odd = 0 , even = 0 ; for ( let i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } document . write ( Math . min ( even , odd ) ) ; } let arr = [ 1 , 2 , 3 ] ; minCost ( arr ) ;