Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Splitit Problem Description Amit is residing in a Paying Guest Accommodation with his friends and has encountered difficulties in tracking their shared expenses as the
Splitit
Problem Description
Amit is residing in a Paying Guest Accommodation with his friends and has encountered difficulties in tracking their shared expenses as the group's spending increased. To address this challenge, Amit decided to develop a mobile application for group expense management and payment settlement. The application aims to streamline group spending by automating expense tracking, group splits, and keeping records of transactions among friends.
Amit maintains a list of expenses in the following format:
Paid ByAmountPersonPersonPerson k
For example, AABC indicates that person A spent which is split among individuals A B and C
Settlements and transactions are recorded as:
Paid ByToAmount eg BA means B paid A
Lent ByToL eg ABL indicates A lend B
The objective is to determine the balances at the end, indicating who owes whom and how much.
A rule is established that if a friend fails to repay a loan within a week, a per annum compound interest, calculated weekly, is applied. The loan is considered paid if the transaction amount equals the incurred interest plus principal.
Rules for Settling two types of Transactions are as mentioned below.
Each line of input corresponds to one day. Only one transaction will happen on each day. Hence, if there are N lines in the input overall time over which all transactions are spread is N days. Use this information to calculate interest on Loans
Expense settlement Non loan transaction:
No specific rules per se Assume all expenses are to be borne equally by friends for whom the expenses are made.
Expense settlement can either be full amount or any arbitrary partial amount.
Loan Repayment:
A person can borrow more than once from the same counter party without settling prior loans.
A person can close at most two loans per transaction for a single lender. Loans owed to different lenders cannot be settled in the same transaction.
The loan is said to be paid if the transaction amount is equal to the incurred interest plus principal.
Since interest is calculated on a weekly basis, payment on any weekday will incur the same amount, for example if interest at the end of week is then payment on any day before end of week will require only to be paid. However, at the end of week if the loan is still unpaid a new interest must be paid.
If a transaction amount equals principal plus interest for two or more loans of the same amount, then consider that this transaction is repaying the first loan. For example, A takes loans from B on Day and same amount on Day then in the th day the interest plus principal will be same for both then the loan payment will be considered for the first one.
Assume that each person will pay only the full amount for closing the loan. No partial payment of loans is permitted.
A transaction can either be an Expense Settlement or Loan Repayment. These two types of transactions cannot be combined.
Reconciliation Rules
Following rules should be adhered to at reconciliation time:
Assume, A owes B owes C expects to receive and D expects to receive then reconciliation should also be in lexicographical order ie A will pay C and B will pay D
Obviously, the above applies only to break ties where amounts are the same. If amounts are unique then reconciliation is straight forward
Reconciliation should include both expense settlement as well as loan repayment amounts
Constraints
A person's name ranges from A to Z
Amount
Transaction and Expenses
Input
The first line contains an integer N representing the number of transactions and expenses.
The next N lines contain the expenses and transactions.
Output
Print who owes whom how much in lexicographical order of the payer. In the format Ignore printing zero balance transactions. If there are no pending dues, print NO DUES."
Time Limit secs
Examples
Example
Input
AABC
BAC
CCA
Output
CA
CB
Explanation
On the first day A spends that is shared equally between A B and C Then B spends that is shared between equally A and C and finally C spends shared equally between C and A
So the final expenditure would be:
A:
B:
C:
Therefore, C will give to A and to B
Example
Input
AABC
BAC
CA
CB
CCA
Output
AC
Explanation
On the first day of input A spends that is shared equally between A B and C On Second day, B spends that is shared equally between A and C By end of Day C owed a total of and A had an outstanding of to receive and B had a total of to receive. Then on third and the fourthday C settled his balance with A and B with amount and On the fifth da
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started