Minimum installment payment

Write codeMedium25 min

Your task

A carrier sells handsets on an installment plan. principal_cents is the amount financed and the account is billed once a month for months statements. At each statement the carrier first adds interest of floor(balance * monthly_rate_bp / 10000) cents, where monthly_rate_bp is the monthly rate in basis points, and then takes the fixed installment. The plan is settled once the balance reaches zero or below, and the closing installment simply takes whatever is left. Return the smallest whole cent installment that settles the account within the given number of statements. Return 0 when nothing is financed, and -1 when a balance is owed but no statement is left to bill it against. An installment no larger than the first month of interest never settles anything, since the debt compounds on itself.

Examples

smallest_installment_cents(principal_cents: int, monthly_rate_bp: int, months: int) -> int
Example 1
Inputsmallest_installment_cents(120000, 150, 12)
Output11002
Example 2
Inputsmallest_installment_cents(50000, 0, 4)
Output12500
Example 3
Inputsmallest_installment_cents(100000, 200, 1)
Output102000