Split Installment Purchases Across Credit Card Invoices

Last updated: November 29, 2026

Quick Overview

Each card purchase has a date, an amount in cents and a number of installments; given the card's monthly closing day, return the total in cents for every invoice month, where installment one lands on the invoice that closes on or after the purchase and any rounding remainder goes to the first installment.

Nubank
Coding & Algorithms
Software Engineer
Nubank
November 29, 2026
Software Engineer
Take-home Project
Coding & Algorithms
Medium

0

0

0 solved


Each card purchase has a date, an amount in cents and a number of installments; given the card's monthly closing day, return the total in cents for every invoice month, where installment one lands on the invoice that closes on or after the purchase and any rounding remainder goes to the first installment.

Parcelado (paying a purchase in interest-free installments) is central to how Brazilians use the Nubank card, and every bill shown in the app is built from these rules. Interviewers use it to see whether you model money in integer cents, handle month and year rollover cleanly and write code that is easy to test.

What the Interviewer Expects
  • Represents money as integer cents and splits with divmod
  • Assigns the first installment by comparing purchase day to closing day
  • Handles December to January rollover with month arithmetic, not string hacks
  • Guarantees the installments sum exactly to the purchase amount
  • Validates bad input such as zero installments
  • Writes or describes small unit tests
Key Topics to Cover
money as integers
date arithmetic
installments
billing cycles
testability
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle a closing day of 31 in February?
  • A purchase is refunded after two installments were billed. How do you represent the credit?
  • How would you add interest for installment plans that carry it?
  • How would you model this so the bill for any past month can be reproduced exactly later?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: ((year, month, day), amount_cents, n) per purchase and closing_day. A purchase on or before the closing day joins that month's invoice; after it, the next month's. Split amount into n p...

High-Level Design

Convert a (year, month) to a single month index year*12 + month-1 so adding k months is plain integer addition. For each purchase find the first invoice month, then add each installment to a `defaul...


Submit Your Answer
Markdown supported

Related Questions