A fleet of deep-space communication relay stations is crewed by rotating engineers. You are given a log of crew-assignment records, each pairing one engineer with the relay station they currently staff. No engineer is ever logged twice at the same station, but the same engineer may crew several different stations. Determine which station(s) currently have the largest crew, and report all of them.
n, the number of assignment records.n lines contains two integers station_id and engineer_id, meaning that engineer engineer_id is assigned to station station_id.Print a single line containing the IDs of every station whose crew size equals the maximum crew size among all stations, in strictly increasing numeric order, separated by single spaces.
Example 1
Input
4 1 100 1 101 2 200 3 300
Expected
1
Explanation
Station 1 has two engineers (100 and 101), while stations 2 and 3 each have only one. The largest crew size is 2, achieved only by station 1, so the output is "1".
Example 2
Input
6 1 10 1 11 2 20 2 21 3 30 4 40
Expected
1 2
Explanation
Stations 1 and 2 each have 2 engineers, while stations 3 and 4 have only 1 each. The maximum crew size of 2 is tied between stations 1 and 2, so both are printed in increasing order: "1 2".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →