List Every Way to Pay Exactly Using Whole Gift Cards
Last updated: November 29, 2026
Quick Overview
A Capital One Shopping user holds gift cards with given balances (values may repeat) and wants to cover a purchase exactly. Return every distinct combination of whole cards, each used at most once, that sums to the purchase amount.
Capital One
November 29, 20260
0
0 solved
A Capital One Shopping user holds gift cards with given balances (values may repeat) and wants to cover a purchase exactly. Return every distinct combination of whole cards, each used at most once, that sums to the purchase amount.
Capital One Shopping rewards can be redeemed as gift cards, which makes combining balances a natural backtracking prompt. The screen checks that you enumerate combinations without duplicates when values repeat and that you prune the search instead of generating every subset.
What the Interviewer Expects
- Sort balances first
- Recurse with a start index so each card is used at most once
- Skip equal values at the same recursion depth to avoid duplicate combinations
- Prune once the current value exceeds the remaining amount
- Copy the path when recording a result
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
- How would you instead return the combination that uses the fewest cards?
- If partial use of one card is allowed, how does the problem change?
- How would you count combinations without listing them, and why is that easier?
- What is the worst case output size, and can any algorithm beat it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: balances in cents, possibly repeating, and a target in cents.
- Each physical card is used whole and at most once.
- Output: all distinct multisets of values summing to the target, each sorte...
High-Level Design
Sort the balances, then backtrack with start and remaining. At each depth, loop i from start; pick card i, recurse from i + 1 (each card once), then undo. Two rules make it efficient and correct: ...