Dsa
Sorting
Medium
Transaction Sorter
You have a list of transactions represented by a tuple with (transaction_id, amount, timestamp). You need to sort this list primarily by amount in descending order and then by timestamp in ascending order in case of ties.
Input:
- The first line contains an integer n (1 <= n <= 1000), the number of transactions.
- The next n lines contain transaction_id (a string), amount (a float), and timestamp (a string in YYYY-MM-DD format).
Output:
- Print each transaction in the sorted order. Each transaction should be printed in the format 'transaction_id amount timestamp'.
Example:
Input:
3
TX1001 150.50 2022-09-01
TX1002 200.75 2022-01-15
TX1003 150.50 2022-02-20
Output:
TX1002 200.75 2022-01-15
TX1001 150.50 2022-09-01
TX1003 150.50 2022-02-20
Key concepts
sortingtransactionsdata handling
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now