Minimize Cost with Replacement with other allowed | This function returns the minimum cost of the array ; Driver code
function getMinCost ( arr , n ) { let min_ele = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { min_ele = Math . min ( min_ele , arr [ i ] ) ; } return min_ele * ( n - 1 ) ; } let arr = [ 4 , 2 , 5 ] ; let n = arr . length ; document . write ( getMinCost ( arr , n ) ) ;