Gift Card Ledger With Expiring Loads and Payment Holds
Last updated: November 29, 2026
Quick Overview
Implement a gift card ledger supporting loads that expire, holds that reserve funds from the soonest-expiring loads, captures for part or all of a hold, voids, and point-in-time available balance.
Square
November 29, 20260
0
0 solved
Implement a gift card ledger supporting loads that expire, holds that reserve funds from the soonest-expiring loads, captures for part or all of a hold, voids, and point-in-time available balance.
Square Gift Cards are used as a tender at checkout, where a payment is authorized (a hold) and later completed or canceled, and promotional value can expire. This onsite coding round checks whether you can design a small stateful money system, keep invariants under partial captures, and reason about time-based edge cases such as a load expiring while it is held.
What the Interviewer Expects
- Spend soonest-expiring funds first
- Make hold replay idempotent by hold id
- Support partial capture that releases the rest
- Define and implement what happens to held funds that expire
- Keep available balance correct at any time t
- State invariants and test them
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 this change if regulation says gift card value cannot expire for some card types?
- How would you persist this so a crash between hold and capture loses no money?
- How would you support refunds back onto the card after capture?
- What if events can arrive slightly out of time order?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Operations with non-decreasing timestamps: load(t, card, amount, expires_at), hold(t, card, hold_id, amount) returning False on insufficient funds, capture(t, hold_id, amount) with amount at mos...
High-Level Design
Each card has a min-heap of lots [expires_at, seq, remaining] keyed by expiry. A hold records which lots it drew from and how much. Capture consumes the hold's portions in the same soonest-expiry or...