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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

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
Union-Find
Connected Components
Path Compression
Union by Rank
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Requirements
  • Input: integer n and a list of pairs (a, b) with 0 <= 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...


Submit Your Answer
Markdown supported