Coinbase OA Interview Question: Transaction Network Balance After Deleting the Nth Transaction

17 Views
No Comments

Given a set of transactions between users and an initial balance per user, output the final balance per user. Note that each transaction denotes the payer->payee relation, and the amount paid is expressed as a percentage.

For example, suppose a given transaction is A->B 20%. This means A paid 20% of whatever he/she had to B.

Introduce an ability to delete a transaction given the user and the transaction’s number with respect to that user. User Y wants to delete their nth transaction. What is the balance of user X?

Example:

User B wants to delete their 2nd transaction (B->D 30%). Note: deletion is by nth transaction with respect to a user.

What is the balance of C?

Input from Level 1:

A has $100

List of transactions:

A->B 20%
A->C 40%
B->D 30%
C->D 50%
C->F 20%
B->E 50%
D->E 25%
F->G 10%
E->C 50%

Execution time limit: 4 seconds (py3)

This problem models a transaction graph where each transfer moves a percentage of the payer’s current balance to the payee, so the final balances depend on transaction order. The main challenge is not only simulating the payments, but also supporting deletion of the nth transaction for a given user and recomputing the resulting balances correctly. A practical solution usually stores transactions grouped by user, tracks balances in a hash map, and replays only the affected part when a transaction is removed.

END
 0