JAVA DISJOINT SET SOLUTION
Here, used "rank" means height of tree\nalways join smaller set with larger set\nusing that it becomes more efficient\nand take less time to find parent\n\nclas
**Here, used "rank" means height of tree\nalways join smaller set with larger set\nusing that it becomes more efficient\nand take less time to find parent**\n```\nclass dsu{\n        int rank[],parent[];\n        dsu(int len){\n            rank = new int[len];\n            parent = new int[len];\n            for(int i=0; i<len; i++) parent[i] = i;\n        }\n        \n        private int findparent(int v){\n            if(parent[v] == v) return v;\n            \n            return parent[v] = findparent(parent[v]);\n        }\n        \n        private void union(int u, int v){\n            if(u == v) return;\n            \n            if(rank[u]==rank[v]){\n                parent[u] = v;\n                rank[v]++;\n            }else{\n                if(rank[u] > rank[v]){\n                    parent[v] = u;\n                }else{\n                    parent[u] = v;\n                }\n            }\n        }\n    }\n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        dsu obj = new dsu(n);\n        boolean ans[] = new boolean[requests.length];\n        int i=0;\n        for(int arr[] : requests){\n            int u=arr[0],v=arr[1];\n            u = obj.findparent(u);\n            v = obj.findparent(v);\n            \n            boolean flag = true;\n            for(int r[] : restrictions){\n                int p1 = obj.findparent(r[0]);\n                int p2 = obj.findparent(r[1]);\n                if((p1==u&&p2==v) || (p1==v&&p2==u)){\n                    flag = false;\n                    break;\n                }\n            }\n            \n            ans[i++] = flag;\n            if(flag){\n               obj.union(u,v);  \n            }\n        }\n        return ans;\n    }\n```
['Java']