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
- Divide the
- Return
allMoney
in the end