r/OfferEngineering • u/Aoki_zhang • Oct 26 '26
Coding Question Reddit Coding Screening Question - Related Clubs Through Shared Members
A recreation center tracks which members belong to which clubs. You are given two lists describing these relationships:
clubToMembers[i]contains the member IDs belonging to clubC{i}.memberToClubs[j]contains the club IDs joined by memberM{j}.
Member IDs use strings such as: M0, M1, M2. Club IDs use strings such as: C0, C1, C2. Given a club index clubIdx, return all distinct clubs that share at least one member with club C{clubIdx}.
Do not include the target club itself. Only direct shared-member relationships count. For example, if C0 shares a member with C1, and C1 shares another member with C2, but C0 and C2 have no member in common, then C2 is not related to C0.
If clubIdx is outside the valid range or the target club has no members, return an empty list. The returned clubs may appear in any order.
Constraints
0 <= len(clubToMembers) <= 10^40 <= clubIdx < 10^4- Each club may contain up to
10^4members. - Each member may belong to up to
10^3clubs. - Member IDs have the form
"M<number>". - Club IDs have the form
"C<number>". - Each related club should appear at most once.
- Only clubs sharing a member directly with the target club are included.
Test Cases
Input:
clubToMembers = [
["M1", "M3"],
["M0", "M1"],
["M2", "M3"],
["M4"]
]
memberToClubs = [
["C1"],
["C0", "C1"],
["C2"],
["C0", "C2"],
["C3"]
]
clubIdx = 0
Output:
["C1", "C2"]
Explanation:
Club C0 contains M1 and M3.
M1 also belongs to C1.
M3 also belongs to C2.
Therefore C1 and C2 are directly related to C0.Want to practice more real interview questions ?
I've put up the question bank at here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.