← 返回 openai 的题目列表Time-Aware Social Network Follow Graph with Recommendations
类型:online_judge
Problem: Time-Aware Social Network Follow Graph + Bidirectional Queries + Recommendations
Design and implement a data structure to maintain follow relationships between users, where a follow becomes active starting at a given time.
Required operations
update(A, B, t): user A starts following B at time t.
check(A, B, t): at time t, determine whether A follows B.
Follow-up 1: Bidirectional queries
Extend the structure to support reverse-direction queries (e.g., who follows B at time t, or whom B follows at time t, as defined by the interviewer).
Follow-up 2: Recommend users (by number of two-hop mediators)
Implement recommend(A) to suggest candidates:
If there exists a path A -> B -> X (A follows B and B follows X), then X is a candidate.
If a candidate X is reachable via multiple distinct mediators (e.g., both A->B->C and A->M->C), it should rank higher.
Example: given A -> B -> C, A -> B -> D, A -> M -> C, recommend C and D to A, with C ranked ahead of D.
Notes
Clarify whether repeated updates, unfollow operations, and monotonic timestamps are allowed.
Clarify whether recommendations are time-dependent (computed on the graph at a query time t).