JAVA | DSU direct application
\n\nclass Solution {\n    int[] parent, rank;\n    \n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        parent = new 
\n```\nclass Solution {\n    int[] parent, rank;\n    \n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        parent = new int[n];\n        rank = new int[n];\n        \n        for(int i = 0; i < n; i++)\n            parent[i] = i;\n        \n        boolean[] ans = new boolean[requests.length]; \n        \n        for(int i = 0; i < requests.length; i++) {\n            int u = requests[i][0];\n            int v = requests[i][1];\n            \n            u = find(u);\n            v = find(v);\n            \n            boolean flag = true;\n            \n            for(int j = 0; j < restrictions.length; j++) {\n                int u_ = restrictions[j][0];\n                int v_ = restrictions[j][1];\n                \n                u_ = find(u_);\n                v_ = find(v_);\n                \n                if((u_ == u && v_ == v) || (u_ == v && v_ == u)) {\n                    flag = false;\n                    break;\n                }\n            }\n            \n            if(flag == true)\n                union(u, v);\n            \n            ans[i] = flag;\n        }\n        \n        return ans;\n    }\n    \n    // Time complexity = O(n^2)\n    // Space complexity = O(n)\n    \n    private int find(int x) {\n        if(parent[x] == x)\n            return x;\n        \n        return parent[x] = find(parent[x]);\n    }\n    \n    private void union(int u, int v) {\n        u = find(u);\n        v = find(v);\n        \n        if(rank[u] > rank[v])\n            parent[v] = u;\n\n        else if(rank[u] < rank[v])\n            parent[u] = v;\n\n        else {\n            parent[u] = v;\n            rank[v]++;\n        }\n    }\n}\n```
[]