
Implement an in-memory banking system that processes a sequence of commands in timestamp order.
accountId
.
CREATE accountId
DEPOSIT accountId amount
amount
to the account.
TRANSFER fromId toId amount
fromId
to
toId
if sufficient funds exist.
TOP_SPENDERS k
k
accounts ranked by
total outgoing spend
(e.g., sum of successful
TRANSFER
amounts sent by the account). Define deterministic tie-breaking (e.g., by
accountId
).
SCHEDULE_PAYMENT fromId toId amount executeAt
executeAt
.
CANCEL_PAYMENT paymentId
MERGE targetId sourceId
sourceId
into
targetId
:
targetId
receives
sourceId
’s remaining balance.
sourceId
(e.g., re-point to
targetId
, or cancel), and ensure the behavior is consistent.
BALANCE accountId
Return outputs for query-like commands (e.g., TOP_SPENDERS, BALANCE, possibly errors) in the order encountered.
You are given N transactions, each with:
id
(unique identifier)
size
(positive integer)
fee
(non-negative integer)
You have a fixed block size limit of 100 (i.e., total size of chosen transactions must be <= 100).
Choose a subset of transactions to maximize total fee.
id
s with a deterministic tie-break rule (e.g., smallest number of transactions; then lexicographically smallest list of ids).
Design an interface and implement a pagination helper over an in-memory collection.
id
).
pageSize
and returning items page-by-page.
getPage(pageNumber)
, or cursor-based
next(cursor)
returning
(items, nextCursor)
), including inputs/outputs.