Initially, you have a bank account balance of 100 dollars.
You are given an integer purchaseAmount representing the amount you will spend on a purchase in dollars.
At the store where you will make the purchase, the purchase amount is rounded to the nearest multiple of 10. In other words, you pay a non-negative amount, roundedAmount, such that roundedAmount is a multiple of 10 and abs(roundedAmount - purchaseAmount) is minimized.
If there is more than one nearest multiple of 10, the largest multiple is chosen.
Return an integer denoting your account balance after making a purchase worth purchaseAmount dollars from the store.
Note: 0 is considered to be a multiple of 10 in this problem.
Example 1:
1 | Input: purchaseAmount = 9 |
Example 2:
1 | Input: purchaseAmount = 15 |
Constraints:
1 | 0 <= purchaseAmount <= 100 |
Approach
1 | Find the lower bould and the upper bound of the amount and round to the cloest value. |
Algorithm
1 | 1. Find the lower bound and upper bound. |
Implementation
1 | int accountBalanceAfterPurchase(int purchaseAmount){ |