An interstellar relay network is built one handshake at a time. Whenever two beacons agree to relay for each other, one beacon sends a handshake request and the other beacon accepts it, and from that moment the two beacons are linked to each other. No unordered pair of beacons ever repeats a handshake, and a beacon never sends a handshake to itself. Mission control wants to know which beacon (or beacons) ended up with the most links once every handshake in the log has been processed.
Print two lines:
Example 1
Input
3 1 2 3 2 3 4
Expected
2 2 3
Explanation
Beacon 1 links with 2 (count 1). Beacon 2 links with 1 and 3 (count 2). Beacon 3 links with 2 and 4 (count 2). Beacon 4 links with 3 (count 1). The maximum count is 2, achieved by beacons 2 and 3, so the output is "2" followed by "2 3".
Example 2
Input
1 1 2
Expected
1 1 2
Explanation
There is only one handshake, between beacons 1 and 2. Each of them ends up with exactly 1 link, so the maximum is 1 and both ids 1 and 2 achieve it.
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 →