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
Coding & Algorithms
Software Engineer
Brex
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
tree traversal
card authorization lifecycle
idempotency
money as integers
state machines
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • add_budget(id, parent, limit), add_card(card, budget).
  • authorize(auth_id, card, amount) -> bool: approve only if used + amount <= limit for 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 ...


Submit Your Answer
Markdown supported

Related Questions