Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Withdraw all money from bank account

Problem :

You have some money in your bank account, the only function to withdraw money is Withdraw(value), if the value is greater than the money you have it returns 0, otherwise it withdraws the requested amount and returns the “value”.

Logic :

  • Start with the maximum value to withdraw – assuming the person is rich 🙂
  • Keep withdrawing money till value becomes 0
    • Divide the value by 2 when withdrawing money returns 0
    • Else add value to allMoney
  • Return allMoney in the end

Solution :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *