Implement Scheduled Bank Payments with Mergeable Accounts and History

Quick Overview

Implement scheduled bank debits, cancellation, spending rankings, account merges, and event-time balance snapshots with correct ordering and history boundaries.

Implement Scheduled Bank Payments with Mergeable Accounts and History

Company: Airbnb

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

Implement accounts with create, deposit, transfer, top-spenders, scheduled-payment, cancellation, merge, and historical-balance operations. Scheduled payments debit an account at their due time if sufficient funds exist, increase outgoing spending on success, and are removed after that one attempt even if funds are insufficient. Process due payments before every public operation, ordered by due time then creation ordinal. ### Constraints & Assumptions Use integer money, positive transaction amounts and delays, and nondecreasing operation timestamps. A historical query's timeAt is no later than the current timestamp. The source's snapshot model treats a merged-away account as absent at and after its merge; do not import the inclusive-merge history rule from a different banking task. Equal-timestamp history reflects the latest processed state at that timestamp. ### Clarifying Questions to Ask - Can deleted account IDs be reused? Whole-state snapshots can distinguish lifetimes by query time. - Are unsuccessful scheduled debits discarded rather than retried? This source implementation does so. - Is delay zero allowed, requiring a defined ordering against the scheduling operation itself? ### Part 1 — Accounts and spending Create unique active accounts at zero balance. Deposit returns the new balance or no result for a missing account. Transfer rejects missing/identical accounts and insufficient funds, otherwise moves money and returns the source balance. Rank active accounts by total outgoing amount descending, then account ID, formatted `account(amount)`. #### What This Part Should Cover - Atomic validation and balance updates. - Outgoing totals from successful transfers and executed scheduled payments only. ### Part 2 — Scheduling and cancellation Schedule a future debit for an existing account, returning sequential IDs `payment1`, `payment2`, etc. Cancel only a still-pending payment owned by the requested account. Due processing happens before cancellation at that timestamp. #### What This Part Should Cover - Stable due-time/ordinal ordering and removal after one execution attempt. - Independent pending-payment identity and ownership validation. ### Part 3 — Merge and history Merge account 2 into account 1, combining balances and outgoing totals, moving pending payments to account 1, and removing account 2 from active state. Reject missing or identical accounts. `get_balance(timestamp, account_id, time_at)` returns that account's balance at time_at or no result when it did not exist then. #### What This Part Should Cover - Reassigned scheduled payments after merge chains. - Snapshots recorded at actual due-event times and after state-changing operations. - Correct account absence at creation/merge boundaries. ```hint A late API call can reveal several earlier events Record a scheduled debit at its due time, not only at the time another operation finally triggers processing. ``` ### What a Strong Answer Covers - One event-ordering helper invoked by every public method, including creation and scheduling. - Correctness-first history with explicitly analyzed snapshot costs. - Tests that interleave due payments, merges, cancellations, and historical reads. ### Follow-up Questions - How would per-account histories reduce whole-state snapshot cost? - Why is calling the settlement helper only from some methods incorrect?

Overview: Implement scheduled bank debits, cancellation, spending rankings, account merges, and event-time balance snapshots with correct ordering and history boundaries.

Read the full Airbnb Software Engineer interview experience this question came from

Airbnb logo
Airbnb
Nov 13, 2026
mediumSoftware EngineerOnline AssessmentCoding & Algorithms
1
0

Implement accounts with create, deposit, transfer, top-spenders, scheduled-payment, cancellation, merge, and historical-balance operations. Scheduled payments debit an account at their due time if sufficient funds exist, increase outgoing spending on success, and are removed after that one attempt even if funds are insufficient. Process due payments before every public operation, ordered by due time then creation ordinal.

Constraints & Assumptions

Use integer money, positive transaction amounts and delays, and nondecreasing operation timestamps. A historical query's timeAt is no later than the current timestamp. The source's snapshot model treats a merged-away account as absent at and after its merge; do not import the inclusive-merge history rule from a different banking task. Equal-timestamp history reflects the latest processed state at that timestamp.

Clarifying Questions to Ask Guidance

  • Can deleted account IDs be reused? Whole-state snapshots can distinguish lifetimes by query time.
  • Are unsuccessful scheduled debits discarded rather than retried? This source implementation does so.
  • Is delay zero allowed, requiring a defined ordering against the scheduling operation itself?

Part 1 — Accounts and spending

Create unique active accounts at zero balance. Deposit returns the new balance or no result for a missing account. Transfer rejects missing/identical accounts and insufficient funds, otherwise moves money and returns the source balance. Rank active accounts by total outgoing amount descending, then account ID, formatted account(amount).

What This Part Should Cover Guidance

  • Atomic validation and balance updates.
  • Outgoing totals from successful transfers and executed scheduled payments only.

Part 2 — Scheduling and cancellation

Schedule a future debit for an existing account, returning sequential IDs payment1, payment2, etc. Cancel only a still-pending payment owned by the requested account. Due processing happens before cancellation at that timestamp.

What This Part Should Cover Guidance

  • Stable due-time/ordinal ordering and removal after one execution attempt.
  • Independent pending-payment identity and ownership validation.

Part 3 — Merge and history

Merge account 2 into account 1, combining balances and outgoing totals, moving pending payments to account 1, and removing account 2 from active state. Reject missing or identical accounts. get_balance(timestamp, account_id, time_at) returns that account's balance at time_at or no result when it did not exist then.

What This Part Should Cover Guidance

  • Reassigned scheduled payments after merge chains.
  • Snapshots recorded at actual due-event times and after state-changing operations.
  • Correct account absence at creation/merge boundaries.

What a Strong Answer Covers Guidance

  • One event-ordering helper invoked by every public method, including creation and scheduling.
  • Correctness-first history with explicitly analyzed snapshot costs.
  • Tests that interleave due payments, merges, cancellations, and historical reads.

Follow-up Questions Guidance

  • How would per-account histories reduce whole-state snapshot cost?
  • Why is calling the settlement helper only from some methods incorrect?