Approve Sharing Requests Without Violating Blocklist Restrictions
Last updated: November 29, 2026
Quick Overview
There are n Drive users and a list of restricted pairs who must never end up in the same sharing group, directly or indirectly. Sharing requests (a, b) arrive in order; approve a request only if merging their groups keeps every restriction satisfied. Return whether each request is approved.
0
0
0 solved
There are n Drive users and a list of restricted pairs who must never end up in the same sharing group, directly or indirectly. Sharing requests (a, b) arrive in order; approve a request only if merging their groups keeps every restriction satisfied. Return whether each request is approved.
Access control in Google Workspace has rules like 'these two orgs must never share data', and this onsite question checks whether you can simulate a merge without committing it. The interviewer looks for testing each restriction against the two roots before the union and for a sensible complexity discussion.
What the Interviewer Expects
- Finds the two roots before deciding
- Rejects the request if any restricted pair spans those two roots
- Approves trivially when both are already in one group
- Only unions after the check passes
- Analyzes O(q * r * alpha(n)) and suggests improvements
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
- With many restrictions, how would you avoid scanning all of them for every request?
- What if approved requests can later be revoked?
- Explain to the user which restriction blocked the request.
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:
n, list of restricted(x, y)pairs, list of requests. - A request is approved if, after merging, no restricted pair shares a group.
- Rejected requests change nothing.
- Output: list of b...
High-Level Design
For a request between groups with roots ra and rb, the merge would violate a restriction exactly when some restricted pair has one member under ra and the other under rb. So compute those two ...