The Process Restricted Friend Requests problem gives you n people, a list of existing restrictions (pairs that cannot be in the same friend group), and a list of friend requests. For each request (u, v), determine if adding the friendship would violate any restriction (directly or transitively). This hard coding problem extends Union-Find with restriction checking. The union find and graph interview pattern is the core.
Google asks this because it tests whether candidates can check if a Union-Find merge would create a group containing any restricted pair. For each potential merge, verify that the resulting component would not contain both endpoints of any restriction.
Union-Find with restriction validation per request. For each request (u, v): temporarily check if merging u and v would violate any restriction. For each restriction (a, b): if find(u)==find(a) and find(v)==find(b), or find(u)==find(b) and find(v)==find(a), then merging would put a and b in the same group → deny request. If no restriction is violated, union u and v and mark request as approved.
n=3, restrictions=[(0,1)], requests=[(0,2),(2,1)].
Process Restricted Friend Requests adds a validation step to standard Union-Find. The key: before each union, check ALL restrictions to ensure no restricted pair would end up in the same component. This O(R * restrictions) per request is acceptable for small inputs. For larger inputs, maintain component restriction sets. Practice "conditional Union-Find" problems where merges have preconditions.