You are given a set of transactions in CSV-like format with columns:
-
account_name
,
timestamp
,
currency
,
amount
Assume:
-
Transactions for all accounts can be interleaved; you must process them in
ascending timestamp order
(if input is already ordered, you may process in given order).
-
All amounts are integers in the smallest currency unit (e.g., cents).
-
Treat each
(account_name, currency)
as a separate balance unless stated otherwise.
Part 1 — Non-zero ending balances
Compute each account’s ending balance (sum of its amounts). Output all accounts whose ending balance is non-zero, along with the balance.
Part 2 — Reject transactions that would make balance negative
Process transactions in time order while maintaining balances.
-
If applying a transaction would make the account’s balance negative,
reject
it (do not apply it).
-
Collect rejected transactions as strings in the original row format (or a clear equivalent such as
"acct,timestamp,currency,amount"
).
Output:
-
The rejected transaction list.
-
All accounts with non-zero ending balances after applying only accepted transactions.
Part 3(a) — Allow borrowing from a platform account
You are also given a platform_id.
Process transactions in time order with this additional rule:
-
For any
non-platform
account, if after applying a transaction its balance would become negative, the account may “borrow” from the platform to bring it back up to 0
as long as the platform has sufficient funds
.
-
Borrow amount =
-(new_balance)
.
-
Decrease the platform’s balance by the borrowed amount.
-
The transaction is accepted if borrowing succeeds.
-
If the platform does not have enough balance to cover the borrow, the transaction is rejected (and not applied).
Additionally compute:
-
max_reserve
: the
maximum total amount borrowed from the platform at any point in time
(i.e., peak borrowed amount outstanding). You should define and track this consistently based on your borrowing model.
Output for Part 3(a):
-
max_reserve
-
rejected_transactions
-
All accounts with non-zero ending balances after processing.
Notes
-
Clearly document how you compute
max_reserve
(e.g., peak cumulative borrowed amount across accounts over time).
-
If multiple currencies exist, state whether borrowing is allowed only within the same currency (recommended) or across currencies (not recommended). Implement the chosen assumption consistently.