Most active user by distinct contacts, then top K

0
Remix

Users send each other messages, and a message between A and B counts as contact for both of them. Build a class with:

  • register(a, b): record a message between a and b.
  • most_active_user(): return the user with the most distinct contacts, in O(1).

Follow-up: return the top k users, where k can change from one call to the next. Other reports framed it as tracking the most active users in a live stream of communication.

GoogleTechnical phone screenLast asked Sep 2026
No answer yet. Write the first one; the best answer gets endorsed.