Deposit Profit

Description


You have deposited a specific amount of dollars into your bank account. Each year your balance increases at the same growth rate. Find out how long it would take for your balance to pass a specific threshold with the assumption that you don’t make any additional deposits.

Example

For deposit = 100, rate = 20 and threshold = 170, the output should be depositProfit(deposit, rate, threshold) = 3.

Each year the amount of money on your account increases by 20%. It means that 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, which is the answer.

Input/Output

  • [execution time limit] 4 seconds (js)

  • [input] integer deposit

The initial deposit as a positive integer.

Guaranteed constraints: 1 ≤ deposit ≤ 100.

  • [input] integer rate

The rate of increase. Each year the balance increases by the rate percent of the current sum.

Guaranteed constraints: 1 ≤ rate ≤ 100.

  • [input] integer threshold

The target balance.

Guaranteed constraints: deposit ≤ threshold ≤ 100.

  • [output] integer

The number of years it would take to hit the threshold.

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
4
5
6
7
8
function depositProfit(deposit, rate, threshold) {
    var i = 0;
    while(deposit < threshold){
        i++;
        deposit += deposit*rate/100;
    }
    return i;
}