A coastal survey team monitors a chain of automated lighthouses, each broadcasting a distinct signal frequency that passing ships can subscribe to for weather and hazard updates. The team logged every subscription event recorded during the survey period as a (ship, lighthouse) pair, and no ship ever subscribes to the same lighthouse twice. For every lighthouse that received at least one subscription, report how many ships subscribed to it, so the harbor office can decide which lighthouses need stronger transmitters.
For every lighthouse_id that appears in the input, print one line "lighthouse_id count" (space-separated), where count is the number of ships subscribed to that lighthouse. Print the lines ordered by lighthouse_id in strictly increasing order. If n is 0, print nothing.
Example 1
Input
4 1 2 2 2 3 1 1 1
Expected
1 2 2 2
Explanation
Ship 1 and ship 2 subscribe to lighthouse 2 (2 ships), and ship 3 and ship 1 subscribe to lighthouse 1 (2 ships). Sorted by lighthouse id ascending, lighthouse 1 is printed first with count 2, then lighthouse 2 with count 2.
Example 2
Input
1 5 100
Expected
100 1
Explanation
There is a single subscription record: ship 5 subscribes to lighthouse 100. Only lighthouse 100 appears, with exactly one subscribing ship, so the output is a single line "100 1".
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 →