← 返回 google 的题目列表Active Communication Top Users
类型:qbank
Process a continuous stream of user pairs such as `A-B` and `B-C`; each pair creates an active communication edge, and the system should output users ordered by current communication count. Follow-ups add self-communication handling, duplicate communication dedupe, and top-K users by count.
Requirements
Input arrives as a stream of user pairs, for example A-B, B-C.
After a pair is accepted, the two users form an active communication.
Maintain each user's active communication count.
Output users ordered by descending communication count.
Clarify tie-breaking before coding; the prompt emphasizes sorted output but does not fix a canonical tie rule.
Follow-ups:
Handle self-communication such as A-A.
Deduplicate an already-existing communication pair.
Return only the top K users, still ordered by count.
Notes
A Java solution used an ordered map / tree structure to keep counts sortable.
The interviewer asked many clarification questions and expected dry runs.
The first version did not require self-communication handling; it was added as a coded follow-up.
Preparation
Implement the pair-normalization layer separately from count maintenance.
Practice maintaining user -> count, edge set, and count -> ordered users views without letting updates drift.
Dry-run duplicate edges and self-edges before discussing top-K optimization.