Count Ways to Split a Repayment Into Allowed Installment Sizes
Last updated: November 29, 2026
Quick Overview
A borrower wants to pay off a balance of `amount` dollars using any number of installments, each of which must be one of the allowed sizes. Count the distinct combinations (order does not matter), modulo 1e9+7.
Upstart
November 29, 20260
0
0 solved
A borrower wants to pay off a balance of `amount` dollars using any number of installments, each of which must be one of the allowed sizes. Count the distinct combinations (order does not matter), modulo 1e9+7.
Upstart's assessment often wraps classic dynamic programming in a lending story, here partial payoff plans on a personal loan. The grader checks that you count combinations rather than orderings and that the DP is linear in the amount per size.
What the Interviewer Expects
- Define ways[t] as the number of combinations reaching total t
- Loop sizes on the outside to avoid counting permutations
- Set the base case ways[0] = 1
- Apply the modulus inside the loop
- State O(amount * sizes) time and O(amount) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Now order matters (a schedule of payments). What single change gives orderings?
- Each size can be used at most once. How does the loop change?
- What if amounts are in cents and the balance is very large?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: non-negative integer amount, a list of distinct positive installment sizes. Output: the number of multisets of sizes summing to amount, mod 1e9+7. Amount 0 has exactly one plan, the empty ...
High-Level Design
This is the unbounded knapsack counting problem. Process sizes one at a time; after processing the first j sizes, ways[t] counts plans that use only those sizes. Adding size s lets every total t ext...