Account Balance
Problem Statement
Given a dataset containing transaction records, do the following:
1. get sum of amount per account Id
2. Handle transactions with insufficient balances and return the results: if there is a transaction that will bring the sum to -ve then add it to rejected transactions and also give the map of account id and positive sum
3.a Add primary account logic: if a balance is insufficient, supplement funds from the primary account (the primary account name is provided as an additional parameter). There is only one platform account and it can be one of the accounts in the initial list. Use a platform account and offset whenever you can, if you can’t then add that transaction to the rejected transaction
Follow-up of 3rd part is replenish the balance of the platform account so maintain a map of which accounts and the sum it took to offset the balance
Transactions transaction1 = new Transactions("acct_123", 1, "usd", 800);
Transactions transaction2 = new Transactions("acct_321", 2, "usd", 100);
Transactions transaction3 = new Transactions("acct_123", 4, "usd", -300);
Transactions transaction4 = new Transactions("acct_321", 5, "usd", -300);
Transactions transaction5 = new Transactions("acct_321", 9, "usd", -800);
Transactions transaction6 = new Transactions("acct_321", 10, "usd", 1000);
List<Transactions> transactionsList = new ArrayList<>();
transactionsList.add(transaction1); transactionsList.add(transaction2); transactionsList.add(transaction3); transactionsList.add(transaction4); transactionsList.add(transaction5); transactionsList.add(transaction6);
if these are the transactions, then for 2nd part
acct_123 would be 500
acct_321 would be 1100
and rejected txns would have
new Transactions("acct_321",5,"usd",-300);
new Transactions("acct_321",9,"usd",-800);
for 3rd part
say acct_123 is the platform account
transaction1 = new Transactions("acct_123",1,"usd",1000);
transaction2 = new Transactions("acct_321",2,"usd",100);
transaction3 = new Transactions("acct_321",4,"usd",-300);
transactionsList = new ArrayList<>();
transactionsList.add(transaction1);
transactionsList.add(transaction2);
transactionsList.add(transaction3);
then acct_123 = 800
acct_321 = 0
for now there are no rejected txns
Some extra info seen on 1p3a:
Basically it’s about calculating account balance. The first 2 parts were simple and could be done using a map. Part 3a involved passing in a platform account, which could be used to cover negative balances in other accounts.