Combine Unique Promo Credits to Exactly Cover a Ride Fare
Last updated: November 29, 2026
Quick Overview
A rider holds promo credits with possibly repeated amounts. Return all distinct combinations of credits (each credit used at most once) whose amounts sum exactly to the fare, with each combination in non-decreasing order.
Uber
November 29, 20260
0
0 solved
A rider holds promo credits with possibly repeated amounts. Return all distinct combinations of credits (each credit used at most once) whose amounts sum exactly to the fare, with each combination in non-decreasing order.
A phone screen backtracking problem with an Uber wallet framing. The interviewer checks for duplicate-free output when input values repeat, and pruning on a sorted list.
What the Interviewer Expects
- Sorts the credits so duplicates are adjacent and pruning works
- Skips equal values at the same recursion depth to avoid duplicate combinations
- Moves to i + 1 so each credit is used once
- Breaks the loop once a value exceeds the remaining amount
- States exponential worst case and why pruning helps
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
- What if each credit can be used unlimited times?
- Return only the combination using the fewest credits.
- How would you handle amounts with cents without floating point errors?
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: list of positive integer credit amounts (cents), positive target fare.
- Output: list of unique combinations, each sorted.
- Each credit at most once....
High-Level Design
Sort the credits. Recurse with a start index and the remaining amount. In the loop over candidates from start, skip credits[i] if it equals credits[i - 1] and i > start, because choosing the s...