Dsa
Queue
Medium
Wagon Loading System
A freight yard is receiving wagons that need to be loaded sequentially into the loading bay. Each wagon has a unique ID and a weight. You must implement a program that loads the wagons into the bay according to their weights: heavier wagons will be loaded last. The program should take N input lines, where the first line contains an integer N (number of wagons), followed by N lines with ID and weight. The output should be the IDs of the wagons in the order they will be loaded.
Example Input:
4
W1 4000
W2 2000
W3 3000
W4 1000
Example Output:
W4 W2 W3 W1
Key concepts
queuesimulation
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