Minimize Cost with Replacement with other allowed | Java Program for the above approach ; This function returns the minimum cost of the array ; Driver code
import java . util . Collections ; import java . util . Arrays ; public class GfG { public static int getMinCost ( Integer arr [ ] , int n ) { int min_ele = Collections . min ( Arrays . asList ( arr ) ) ; return min_ele * ( n - 1 ) ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 4 , 2 , 5 } ; int n = arr . length ; System . out . println ( getMinCost ( arr , n ) ) ; } }