Authorize Card Swipes Against Nested Budget Limits With Holds
Last updated: November 29, 2026
Quick Overview
Implement a spend ledger where budgets form a tree, each card draws from one budget, and an authorization is approved only if the amount fits under the remaining limit of that budget and every ancestor. Support settling a hold at a different final amount, reversing a hold, and idempotent retries of the same authorization id.
Brex
November 29, 20260
0
0 solved
Implement a spend ledger where budgets form a tree, each card draws from one budget, and an authorization is approved only if the amount fits under the remaining limit of that budget and every ancestor. Support settling a hold at a different final amount, reversing a hold, and idempotent retries of the same authorization id.
Brex lets a company nest budgets (company, department, team, trip) and issue cards against them, so every swipe must be checked against a chain of limits in real time. This practical coding round looks at clean object modeling, correct money handling, and the card lifecycle of hold, settle and reverse, rather than a trick algorithm.
What the Interviewer Expects
- Models budgets as a parent pointer tree and checks every ancestor before mutating anything
- Treats a hold as consuming budget until it settles or is reversed
- Handles settlement at a different amount, including forced posts that overrun
- Makes authorize idempotent on auth id so network retries do not double spend
- Uses integer cents and explains complexity in terms of tree depth
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
- Holds that never settle should expire after a few days. How would you add that?
- How would this work when many authorizations for the same department arrive concurrently across servers?
- Limits reset monthly but a hold placed on the 31st settles on the 2nd. Which period does it count against?
- How would you add merchant category rules, for example a travel budget that declines restaurants?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
add_budget(id, parent, limit),add_card(card, budget).authorize(auth_id, card, amount) -> bool: approve only ifused + amount <= limitfor the card's budget and all ancestors. Approval pl...
High-Level Design
Store parent, limit and used per budget. Each auth keeps [card, amount, state] where state is HELD, SETTLED, REVERSED or DECLINED. Every money change is a delta applied along the path ...