This question evaluates object-oriented design and stateful system skills, including time-ordered event processing, scheduling and cancellation semantics, balance accounting, and top-k aggregation using appropriate data structures.
Design an in-memory banking system that supports:
timestamp
.
t
, the system must
process all scheduled transfers
whose execution time
<= t
.
create_account(timestamp, customer_id) -> bool
deposit(timestamp, customer_id, amount) -> bool
withdraw(timestamp, customer_id, amount) -> bool
transfer(timestamp, from_id, to_id, amount) -> bool
amount
toward
from_id
spending.
top_spending(timestamp, n) -> list<string>
n
customers formatted
"customerId(total)"
.
schedule_transfer(timestamp, from_id, to_id, amount, delay) -> string | null
timestamp + delay
.
null
.
transfer_id
for cancellation.
cancel_transfer(timestamp, customer_id, transfer_id) -> bool
transfer_id
exists
customer_id
is the sender
merge_account(timestamp, from_id, to_id) -> bool
from_id
into
to_id
:
to_id
from_id
as sender or receiver to reference
to_id
from_id