Maximum money that can be withdrawn in two steps | Function to return the maximum coins we can get ; Update elements such that X > Y ; Take from the maximum ; Refill ; Again , take the maximum ; Driver code
function maxCoins ( X , Y ) { if ( X < Y ) { let temp = X ; X = Y ; Y = temp ; } let coins = X ; X -- ; coins += Math . max ( X , Y ) ; return coins ; } let X = 7 , Y = 5 ; document . write ( maxCoins ( X , Y ) ) ;