Minimum cost to empty Array where cost of removing an element is 2 ^ ( removed_count ) * arr [ i ] | Function to find the minimum cost of removing elements from the array ; Sorting in Increasing order ; Loop to find the minimum cost of removing elements ; Driver Code ; Function call
function removeElements ( arr , n ) { arr . sort ( ( a , b ) => b - a ) ; var ans = 0 ; for ( var i = 0 ; i < n ; i ++ ) { ans += arr [ i ] * Math . pow ( 2 , i ) ; } return ans ; } var n = 4 ; var arr = [ 3 , 1 , 2 , 3 ] ; document . write ( removeElements ( arr , n ) ) ;