Savings With Interest
A savings account holds start coins. At the end of every month two things happen, in this order: the bank adds interest of one coin for every full 10 coins in the account, and then you pay in deposit coins.
Return the balance after months months.
Example 1
start 100
deposit 5
months 2
returns 131
Month 1: 100 earns 10 and gets 5 more, 115. Month 2: 115 earns 11 and gets 5 more, 131.
Example 2
start 4
deposit 1
months 3
returns 7
Fewer than 10 coins earn nothing, so only the deposits count: 5, 6, 7.
Example 3
start 250
deposit 40
months 0
returns 250
No month has passed.
Constraints
0 <= start <= 10000 <= deposit <= 1000 <= months <= 40
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Dynamic programming problems
- Stacked CansBeginner
- Sum of the Last kBeginner
- Take One, Two or ThreeBeginner
- Three Button CalculatorBeginner
- Broken StairsEasy
- Cheapest Toll RouteEasy
- Evenly Spaced RunsEasy
- Fewest Coins for the FareEasy