← Questions

Most active user by distinct contacts, then top K

0
GoogleCodingLast asked Sep 2026

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.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding