01 · Question
You receive a list of (IP address, username) connections. IP addresses are unique, but a username may appear more than once.
Return the username with the most connections. If several usernames tie, return any of them.
Example:
- Input:
[("203.0.113.16", "mike"), ("198.51.100.25", "bob"), ("192.0.2.5", "mike")] - Output:
"mike"
02 · Analysis
Use a frequency map from username -> connection count. Build the counts in one pass, then scan the map for the largest value.
The second pass visits at most as many usernames as there are connections, so the total remains time. The map uses space for unique usernames.