Dsa
Sorting
Easy
Transaction Record Sorter
You are keeping track of transaction records. Each record includes a transaction ID and the amount. Sort the records first by the amount in descending order and then alphabetically by transaction ID if the amounts are the same. The input begins with an integer followed by that many lines of transaction records in the format 'transaction_id amount'. Output the records sorted on new lines with the original format.
Example:
Input:
3
abc123 200
xyz456 150
def789 200
Output:
abc123 200
def789 200
xyz456 150
Key concepts
sortingtupleslists
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