2076. Process Restricted Friend Requests
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {
        boolean[] response = new boolean[requests.length];

        Set<Integer>[] blockList = new Set[n];
        int[] leader = new int[n];

        for (int i = 0; i < n; i++) {
            leader[i] = i;
            blockList[i] = new HashSet<>();
        }

        for (int[] pair : restrictions) {
            blockList[pair[0]].add(pair[1]);
            blockList[pair[1]].add(pair[0]);
        }

        for (int i = 0; i < requests.length; i++) {
            int user1 = findLeader(leader, requests[i][0]);
            int user2 = findLeader(leader, requests[i][1]);
            Set<Integer> blockedUser1 = blockList[user1];
            Set<Integer> blockedUser2 = blockList[user2];

            if (user1 == user2) {
                response[i] = true;
            } else if (!blockedUser1.contains(user2) && !blockedUser2.contains(user1)) {
                leader[user2] = user1;
                blockedUser1.addAll(blockedUser2);
                for (int blocked : blockedUser2) {
                    blockList[blocked].add(user1);
                }
                response[i] = true;
            } else {
                response[i] = false;
            }
        }

        return response;
    }

    private int findLeader(int[] leader, int person) {
        if (leader[person] != person) {
            leader[person] = findLeader(leader, leader[person]);
        }
        return leader[person];
    }
}

```
['Java']