#C10114. Financial Transaction Analyzer
Financial Transaction Analyzer
Financial Transaction Analyzer
Description: This problem requires you to analyze a list of financial transactions provided via standard input.
Each transaction consists of a date, a description, and an amount. You need to calculate the total income (sum of all positive transactions), the total expense (sum of all negative transactions), and the net balance computed as $$\text{net_balance} = \text{total_income} + \text{total_expense}.$$
Additionally, output two lists: one for income transactions and one for expense transactions sorted in ascending order by date. Also, determine the highest income transaction (the income transaction with the greatest amount, or the first occurrence in case of a tie) and the largest expense transaction (the expense transaction with the smallest value, or the first occurrence in case of a tie). If no transaction exists in a category, output null for that field.
inputFormat
Input:
The first line contains an integer T representing the number of transactions.
Each of the next T lines contains three space-separated values:
1. Date in the format YYYY-MM-DD
2. Description (a single word with no spaces)
3. Amount (a floating-point number; positive for income and negative for expense)
outputFormat
Output:
Print a JSON object to standard output with the following keys:
- total_income: Sum of all income amounts
- total_expense: Sum of all expense amounts
- net_balance: Sum of total_income and total_expense
- income_transactions: A list of income transactions sorted by date (each represented as an object with keys: date, description, amount)
- expense_transactions: A list of expense transactions sorted by date
- highest_income_transaction: The income transaction with the highest amount (or null if none)
- largest_expense_transaction: The expense transaction with the lowest amount (or null if none)## sample
5
2023-01-01 Salary 3000.0
2023-01-03 Rent -1200.0
2023-01-05 Groceries -100.5
2023-02-01 Freelance 1500.0
2023-02-02 Gym -50.0
{"total_income": 4500.0, "total_expense": -1350.5, "net_balance": 3149.5, "income_transactions": [{"date": "2023-01-01", "description": "Salary", "amount": 3000.0}, {"date": "2023-02-01", "description": "Freelance", "amount": 1500.0}], "expense_transactions": [{"date": "2023-01-03", "description": "Rent", "amount": -1200.0}, {"date": "2023-01-05", "description": "Groceries", "amount": -100.5}, {"date": "2023-02-02", "description": "Gym", "amount": -50.0}], "highest_income_transaction": {"date": "2023-01-01", "description": "Salary", "amount": 3000.0}, "largest_expense_transaction": {"date": "2023-01-03", "description": "Rent", "amount": -1200.0}}