Refunds take the oldest payment
transcript
A customer pays five units twice. Then asks for one refund. Which payment does it return?
Finance has a rule: oldest first. So the refund takes payment zero. Payment one keeps waiting.
A stack gives the newest payment. That is payment one. Either way, one refund is matched.
The count of matches looks right. Only the link to the payment is wrong. And finance needs the link.
Keep a map of queues instead. The key is customer and amount. Payments in at the back, refunds out the front.
Write a test with two equal payments. Then add one refund of the same amount. The refund must take payment zero. A stack fails this test at once.
The key needs the customer too. Another customer's payment never matches. Even when the amount is the same.
Oldest first means a queue. Check the links, not the count. Full breakdown in the lecture.