Java Union Find Solution With Comment
\nclass Solution {\n    int[] parent;\n    boolean[] result;\n    \n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n      
```\nclass Solution {\n    int[] parent;\n    boolean[] result;\n    \n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        parent = new int[n];\n        for (int i = 0; i < n; i++) {\n            parent[i] = i;\n        }\n        result = new boolean[requests.length];\n        \n        for (int i = 0; i < requests.length; i++) {\n            // personA and personB can become friends if for all restrictions\n            // person x_i and person y_i are not in the same set as personA and personB\n            // and vice versa\n            int personA = requests[i][0];\n            int personB = requests[i][1];\n            int personASetRepresentative = find(personA);\n            int personBSetRepresentative = find(personB);\n            boolean flag = true;\n            for (int[] restriction : restrictions) {\n                int blackListPersonARepresentative = find(restriction[0]);\n                int blackListPersonBRepresentative = find(restriction[1]);\n                if (personASetRepresentative == blackListPersonARepresentative && personBSetRepresentative == blackListPersonBRepresentative) {\n                    flag = false;\n                }\n                if (personASetRepresentative == blackListPersonBRepresentative && personBSetRepresentative == blackListPersonARepresentative) {\n                    flag = false;\n                }\n            }\n            if (flag) {\n                union(personA, personB);\n            }\n            result[i] = flag;\n        }\n        return result;\n    }\n    \n    private int find(int node) {\n        int root = node;\n        while (parent[root] != root) {\n            root = parent[root];\n        }\n        \n        //path compression\n        int curr = node;\n        while (parent[curr] != root) {\n            int next = parent[curr];\n            parent[curr] = root;\n            curr = next;\n        }\n        return root;\n    }\n    \n    private boolean union(int node1, int node2) {\n        int root1 = find(node1);\n        int root2 = find(node2);\n        if (root1 == root2) {\n            return false;\n        }\n        parent[root2] = root1;\n        return true;\n    }\n}\n```
['Union Find', 'Java']