Match Merchant Refunds to Original Card Charges
Last updated: November 29, 2026
Quick Overview
Given card charges and refunds in time order, each with an id, merchant name and amount in cents, pair every refund with the earliest still-open charge at the same merchant for the same amount. Return the matched pairs and the refunds that could not be matched.
SoFi
November 29, 20260
0
0 solved
Given card charges and refunds in time order, each with an id, merchant name and amount in cents, pair every refund with the earliest still-open charge at the same merchant for the same amount. Return the matched pairs and the refunds that could not be matched.
SoFi Money and the SoFi credit card show refunds next to the purchase they reverse, and disputes teams need unmatched refunds surfaced. This screen checks whether you reach for a hash map keyed on the right composite key and whether you think about normalization and one-to-one matching.
What the Interviewer Expects
- Uses a composite key of normalized merchant and integer amount
- Keeps a FIFO queue per key so each charge is consumed at most once
- Uses integer cents, never floats, for amounts
- Returns unmatched refunds rather than silently dropping them
- States O(n + m) time and discusses memory for long histories
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 handle partial refunds that are smaller than the charge?
- What changes if refunds can arrive before the charge settles?
- How would you match when the refund merchant descriptor differs slightly from the charge?
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 are two lists of (id, merchant, amount_cents), both in time order. A refund matches a charge with the same merchant (case and whitespace insensitive) and the same amount. Each charge can back...
High-Level Design
Index charges by (normalized_merchant, amount) into a deque of charge ids in arrival order. For each refund, look up its key; if the deque is non-empty pop from the left and record the pair, otherwi...