Tally Expenses

Description

Build an app that can tally expenses among friends.

Endpoint

Provide a POST endpoint /tally-expense that given 1 set of input will return 1 set of output

Input

The HTTP POST request will come with a body of Content-Type: application/json .

{
    "name": "Jan Expense Report",
    "persons": ["Alice", "Bob", "Claire", "David"],
    "expenses": [
        {
            "category": "Breakfast",
            "amount": 60,
            "paidBy": "Bob",
            "exclude": ["Claire","David"]
        },
        {
            "category": "Phone Bill",
            "amount": 100,
            "paidBy": "Claire"
        },
        {
            "category": "Groceries",
            "amount": 80,
            "paidBy": "David"
        },
        {
            "category": "Petrol",
            "amount": 40,
            "paidBy": "David"
        }
    ]
}

Output

There may be many different solutions but you just need to return one of the solutions which settle the expenses correctly among friends. Here is an example.

{
    "transactions": [
        {
            "from": "Alice",
            "to": "Claire",
            "amount": 45
        },
        {
            "from": "Alice",
            "to": "David",
            "amount": 40
        },
        {
            "from": "Bob",
            "to": "David",
            "amount": 25
        }
    ]
}

Another possibility is:

{
    "transactions": [
        {
            "from": "Alice",
            "to": "David",
            "amount": 65
        },
        {
            "from": "Alice",
            "to": "Claire",
            "amount": 20
        },
        {
            "from": "Bob",
            "to": "Claire",
            "amount": 25
        }
    ]
}

Limits

1N2147483647. N - Number of friends
1T < 100000. T - Number of expenses
0.00 ≤ X ≤ 3.4028235E6 X - Expense amount (you should round it upto 2 decimal places using rounding mode HALF_UP)
HTTP request timeout: 60s

Notes

An expense can exclude certain members. Excluded members don't need to contribute for that expense.

Round the decimal values up to 2 decimal places using rounding mode HALF_UP