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
valueto withdraw - assuming the person is rich :) - Keep withdrawing money till
valuebecomes 0- Divide the
valueby 2 when withdrawing money returns 0 - Else add value to
allMoney
- Divide the
- Return
allMoneyin the end