Java | Clean | Union Find
```\nclass Solution {\n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        DSU dsu = new DSU(n, restrictions);\n      
```\nclass Solution {\n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        DSU dsu = new DSU(n, restrictions);\n        int r = requests.length;\n        boolean res[] = new boolean[r];\n        for(int i = 0; i < r; i++) {\n            int req[] = requests[i];\n            res[i] = dsu.union(req[0], req[1]);\n        }\n        return res;\n    }\n    \n    static class DSU {\n        \n        Map<Integer, Set<Integer>> cmpToNodes = new HashMap<>();\n        int parent[];\n        int[][] restrictions;\n        DSU(int n, int[][] restrictions) {\n            parent = new int[n];\n            for(int i = 0; i < n; i++) {\n                Set s = new HashSet<>();\n                s.add(i);\n                cmpToNodes.put(i, s);\n                parent[i] = i;\n            }\n            this.restrictions = restrictions;\n        }\n        \n        int find(int u) {\n            if(u == parent[u]) return u;\n            return parent[u] = find(parent[u]);\n        }\n        \n        boolean union(int u, int v) {\n            int pu = find(u);\n            int pv = find(v);\n            \n            if(pu != pv) {\n                Set<Integer> setU = cmpToNodes.get(pu);\n                Set<Integer> setV = cmpToNodes.get(pv);\n                for(int restrict[] : restrictions) {\n                    int x = restrict[0];\n                    int y = restrict[1];\n                    boolean foundX = setU.contains(x) || setV.contains(x);\n                    boolean foundY = setU.contains(y) || setV.contains(y);\n                    if(foundX && foundY) return false;\n                }\n                setV.addAll(setU);\n                parent[pu] = parent[pv];\n            }\n            return true;\n        }\n    }\n}
[]