Problem: You have deposited a specific amount of money into your bank account. Each year your balance increases at the same growth rate. With the assumption that you don't make any additional deposits, find out how long it would take for your balance to pass a specific threshold.
Example:
For deposit = 100, rate = 20, and threshold = 170, the output should be
depositProfit(deposit, rate, threshold) = 3.
Each year the amount of money in your account increases by 20%. So throughout the years, your balance would be:
- year 0: 100;
- year 1: 120;
- year 2: 144;
- year 3: 172.8.
Thus, it will take 3 years for your balance to pass the threshold, so the answer is 3.
-Summary-
1. Create a variable "years" to count years until deposit over the threshold.
2. Create a while loop to calculate the deposit amount every year with an increase by rate.
3. Once deposit over the threshold, loop stop and return with counted years
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Arcade' 카테고리의 다른 글
CodeSignal [33/60] stringsRearrangement (1) | 2020.05.23 |
---|---|
CodeSignal [32/60] absoluteValuesSumMinimization (0) | 2020.05.22 |
CodeSignal [30/60] circleOfNumbers (0) | 2020.05.21 |
CodeSignal [29/60] chessBoardCellColor (0) | 2020.05.20 |
CodeSignal [28/60] alphabeticShift (0) | 2020.05.19 |
댓글