Dsa
Sorting
Easy
Auction Profit Maximizer
An auction house tracks items by 'ItemName ReservePrice CurrentBid'. They want to rank items based on 'Net Profit' (CurrentBid minus ReservePrice).
1. Rank items by Net Profit in descending order.
2. If Net Profit is tied, rank by the CurrentBid in descending order.
3. If still tied, sort alphabetically by ItemName.
Input Format:
- An integer N.
- N lines: 'ItemName ReservePrice CurrentBid'.
Output Format:
- The sorted ItemNames, one per line.
Example:
Input:
2
Painting 100 150
Statue 200 250
Output:
Painting
Statue
(Both have profit 50, but Painting is alphabetically first? No, rule 2: Tied profit, then higher CurrentBid. Statue 250 > Painting 150. So Statue comes first.)
Key concepts
calculated fieldsdescending sort
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