Count Shared Drive Collaboration Groups From Sharing Events
Last updated: November 29, 2026
Quick Overview
Given n Google Drive users labeled 0 to n-1 and a list of sharing events (a, b) meaning a shared a folder with b, return how many collaboration groups exist, where a group is any set of users linked directly or transitively by sharing.
0
0
0 solved
Given n Google Drive users labeled 0 to n-1 and a list of sharing events (a, b) meaning a shared a folder with b, return how many collaboration groups exist, where a group is any set of users linked directly or transitively by sharing.
A warm-up in a Google phone screen that checks whether you recognize connected components and can write a clean disjoint set union from memory. The interviewer watches for path compression, union by rank, and the trick of decrementing a counter on every successful merge instead of counting roots at the end.
What the Interviewer Expects
- Identifies the problem as counting connected components
- Implements find with path compression or halving
- Uses union by rank or size to keep trees shallow
- Decrements a group counter only on successful merges
- Handles self-shares and duplicate events
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you also return the size of the largest group?
- What changes if sharing events stream in and you must answer the group count after each one?
- When would BFS or DFS be preferable to union-find here?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: integer
nand a list of pairs(a, b)with0 <= a, b < n. - Sharing is treated as symmetric for grouping: if a shared with b, they are in the same group.
- Duplicates and self-pairs `(a,...
High-Level Design
Start with every user in their own set, so the answer begins at n. Each sharing event is a union. A union between two users already in the same set changes nothing; a union across two sets reduces t...