Minimum Transactions
Description:
This Kata is a bit more optimized version of minimum account balancing problem.
You are given a list of transactions between people in the form of ( payer, payee, amount )
.
This means payer
pays amount
to payee
, so that payee
owes amount
to payer
.
Return the list of minimum number of transactions, with minimum amount of total money transferred, so that everyone pays back what they owed. Each transaction should be in the form of ( payer, payee, amount )
.
Example #1
l = [(3, 0, 7), (3, 1, 5), (3, 2, 1), (4, 2, 7)]
min_transaction(l) = [(2, 3, 8), (0, 4, 7), (1, 3, 5)]
Input/Output means
- Person
0
took7
, so should give7
in total - Person
1
took5
, so should give5
in total - Person
2
took8
, so should give8
in total - Person
3
gave13
, so should get13
in total - Person
4
gave7
, so should get7
in total
We can balance these transactions with the following 3
transactions:
- Person
2
pays8
to person3
- Person
1
pays5
to person3
- Person
0
pays7
to person4
Example #2
l = [(4, 1, 7), (4, 8, 7), (1, 8, 22), (8, 2, 24), (1, 8, 21), (8, 1, 8)]
Possible solution -> [(2, 1, 24), (8, 1, 4), (8, 4, 14)]
Alternative solution -> [(2, 4, 14), (2, 1, 10), (8, 1, 18)]
Constraints
- Number of people will not exceed
8
- Transaction list can contain up to
100
transactions - Transaction amount cannot be negative
- In the resulting list, some people can owe money to someone that s/he didnt take money directly from. That is fine; we are trying to minimize the number oftransactions and ( then ) the minimum amount of money that should be transferred
If there is no one that should pay anything just return empty list.
There can be multiple solutions. It is enough to return one of them.
Your solution will be tested in terms of correct minimum transaction count, correct minimum transaction amount, and people paying or receiving exactly what they owe or are owed.
Transaction order is not important.
Similar Kata:
Stats:
Created | May 8, 2020 |
Published | May 8, 2020 |
Warriors Trained | 83 |
Total Skips | 4 |
Total Code Submissions | 266 |
Total Times Completed | 10 |
Python Completions | 8 |
JavaScript Completions | 5 |
Haskell Completions | 1 |
Total Stars | 11 |
% of votes with a positive feedback rating | 90% of 5 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 4 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 4 kyu |