Dsa
Sorting
Warm-up
The Fragile Warehouse Robot
A warehouse robot needs to sort packages for delivery. Each package has a weight (integer), a type ('Fragile' or 'Standard'), and a unique label (string). The robot must sort the packages primarily by weight in ascending order. If two packages have the same weight, 'Fragile' packages must come before 'Standard' packages. If they have the same weight and type, sort them alphabetically by their label.
Input: The first line contains an integer N, the number of packages. The next N lines each contain: Weight Type Label.
Output: Print the labels of the sorted packages, one per line.
Example Input:
3
10 Standard BoxC
5 Fragile BoxB
10 Fragile BoxA
Example Output:
BoxB
BoxA
BoxC
Key concepts
sortingstable sortmultiple keys
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