Given a mapping of communities to their followers, find communities that are related to a target community through shared followers.
Part 1 — Direct Relations (degree=1): Two communities are "related" if they share at least one follower. Given a target community, return all directly related communities.
Part 2 — Degrees of Separation:
Extend the solution to find communities related up to degree levels of indirect relationship. At each degree, find communities directly related (sharing followers) to the communities discovered at the previous degree. Return all communities found across all degrees.
Input:
community_data: Array of strings in format "CommunityID:Follower1,Follower2,..."target: The community ID to find relations fordegree: Maximum degrees of separation (1 = direct relations only)Return a sorted list of all related community IDs (excluding the target itself).
Example Walkthrough: ` community_data = ["C1:F1,F3", "C2:F1,F2", "C3:F2", "C4:F3"]
Community → Followers: C1:[F1,F3] C2:[F1,F2] C3:[F2] C4:[F3] Follower → Communities: F1:[C1,C2] F2:[C2,C3] F3:[C1,C4]
findRelatedCommunities("C4", degree=1) → ["C1"] C4 has follower F3, who also follows C1.
findRelatedCommunities("C4", degree=2) → ["C1", "C2"] Degree 1: C1 (shared follower F3 with C4) Degree 2: C2 (shared follower F1 with C1)
findRelatedCommunities("C2", degree=1) → ["C1", "C3"] C2 has F1 (also in C1) and F2 (also in C3). `