Build an EMI calculator: monthly payment, amortization schedule and exact rounding to the paisa
Problem
Loan calculators are a common machine coding task in Indian fintech interviews (banks, Groww, Paytm, CRED): the UI is simple, and the interviewer watches how you handle the money. Write the engine behind one: emiPlan({ principal, annualRate, months }).
{
emi, // the monthly payment, in rupees, rounded to the paisa
totalPayment, // everything paid over the loan
totalInterest, // totalPayment - principal
schedule, // one row per month: { month, payment, interest, principal, balance }
}Ref. UR-1433 · © UIRound · uiround.com/questions/build-an-emi-calculator-monthly-payment-amortization-schedule-and-exact-rounding-to-the-paisa
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 2
- code listings
- 5
- edge cases
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1The EMI formula is P × r × (1 + r)^n / ((1 + r)^n − 1), with r the monthly rate (annual percent / 12 / 100) and n the number of months. A 0% loan divides by zero, so handle it separately.
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.