Java 🔥 | Comments✔ | Clean Code✔ | Simple Explanation🔥✅
Intuition\nMake them friend first, and then check if parent of restriction node belongs to same component or not \nIf they belong to same component then revert 
# Intuition\nMake them friend first, and then check if parent of restriction node belongs to same component or not \nIf they belong to same component then revert back your ans\nIf not then mark your answer as true and continue for others.\n\n# Code\n```\nclass Solution {\n    class Disjoint{ //basic disjoint class tempelate\n        int V;\n        int[] parent,size;\n\n        Disjoint(int V){\n            this.V=V;\n            parent=new int[V];\n            size=new int[V];\n            for(int i=0; i<V; i++){\n                parent[i]=i;\n                size[i]=1;\n            }\n        }\n\n    int findParent(int x){\n        if(parent[x]==x)\n        return x;\n        return findParent(parent[x]);\n    }\n\n    void unionBySize(int x,int y){\n        int px=findParent(x);\n        int py=findParent(y);\n\n        if(px==py)return ;\n        if(size[px]<size[py]){\n            size[py]+=size[px];\n            parent[px]=py;\n        }else{\n             size[px]+=size[py];\n            parent[py]=px;\n        }\n    }\n\n\n    }\n    public boolean[] friendRequests(int n, int[][] rest , int[][] requests) {\n        Disjoint ds=new Disjoint(n);\n        boolean[] ans=new boolean[requests.length];\n        Arrays.fill(ans,true);\n\n        for(int i=0; i<requests.length; i++){\n            int x=requests[i][0];\n            int y=requests[i][1];\n\n            int opx=ds.findParent(x);// old parent of x\n            int opy=ds.findParent(y);// old parent of y\n\n                 ds.unionBySize(x,y);   // make them friend irrespective of restrictions\n\n             if( isRuleVoilated(rest,ds)){// now check if any restriction rule is voilated.\n                   ds.parent[opx]=opx;  // if rule is violated then restore.\n                 ds.parent[opy]=opy;    // parent of x and y should point them self showing they were not friend.\n                 ans[i]=false; // mark ans as false\n             }\n\n          // remember ans is filled with true. So no need to add ans[i]=true;\n        }\n        return ans;\n    }\n\n\n    boolean isRuleVoilated(int[][] res,Disjoint ds){\n        for(int i=0; i<res.length; i++){\n            int p1=ds.findParent(res[i][0]);\n            int p2=ds.findParent(res[i][1]);    // if  parent of both restriction node belongs to same component then notify rule is voilated \n\n            if(p1==p2){\n                return true;\n            }\n        }\n        return false;\n    }\n}\n```\n# Upvote button is below, don\'t mind hitting it \uD83E\uDD24\n
['Java']