Algorithm · Stripe · Hard
Write process_events(events, surcharge_rates), which replays a log of payment events in time order. When a customer makes a purchase, their gift card balances are consumed first, and whatever is left over is billed to their credit card. The task is built up across four parts, each adding to the previous one; your final code has to handle all four at once. Every amount of money is a non-negative integer number of cents, and each customer starts out with a gift card balance of…