You are given a list of transaction records as strings. Each record has the format:
account_id,timestamp,currency,amount
account_id
: string identifier
timestamp
: integer (not guaranteed sorted)
currency
: string like
USD
,
EUR
amount
: integer (can be positive for credit or negative for debit)
Maintain balances per (account_id, currency).
Process all transactions and return the final balance for each (account_id, currency).
0
.
Now process transactions in increasing timestamp order (tie-breaker can be input order).
A transaction is rejected if applying it would make that account’s balance for that currency fall below 0.
Add support for a special “platform” account that can cover shortfalls. You are given platform_account_id as a parameter.
Processing is still in timestamp order. For a debit transaction (negative amount) on account A in currency C:
A
has enough balance in
C
, apply it normally.
C
:
A
(bringing it to
0
).
C
,
reject
the transaction (no balances change).
Credits (positive amount) always apply.
Return final non-zero balances for all accounts (including the platform account if non-zero).
timestamp
fits in 64-bit integer
amount
fits in 64-bit signed integer