Code RoomMinimum installment payment
MediumPrep Room Coding #4919

Minimum installment payment

CodingAlgorithms & data structuresMid–Senior~25 min

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.

Implement
smallest_installment_cents(principal_cents: int, monthly_rate_bp: int, months: int) → int
Examples
in[120000,150,12]out11002
in[50000,0,4]out12500
in[100000,200,1]out102000
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[120000,150,12]11002not run yetsample
[50000,0,4]12500not run yetsample
[100000,200,1]102000not run yetsample