👥Process Restricted Friend Request👥 - 🔗Union Find🔗
Intuition\nThe problem can be solved using a Union-Find data structure, which allows us to efficiently manage the friend relationships between people. We iterat
# Intuition\n*The problem can be solved using a Union-Find data structure, which allows us to efficiently manage the friend relationships between people. We iterate through each friend request and check if the two people can become friends by verifying that they don\'t have any restrictions. If they can become friends, we union their groups. We use the find function to determine the root of each person\'s group, and the parent array to store the parent of each person.*\n# Approach\n# 1. Initialize the parent array\n* We create a parent array of size n, where parent[i] represents the parent of person i. Initially, each person is their own parent, so we set parent[i] = i for all i.\n\n# 2. Process each friend request\n* We iterate through each friend request in the requests array. For each request, we find the roots of the two people involved using the find function.\n\n# 3. Check for restrictions\n* We iterate through each restriction in the restrictions array. If the roots of the two people involved in the request match with the roots of the restricted people, we set the result for this request to false and break out of the loop.\n\n# 4. Union the groups\n* If there are no restrictions, we union the groups of the two people involved in the request by setting the parent of one person to the other.\n\n# 5. Return the results\n* Finally, we return the ans array, which contains the result of each friend request.\n# Complexity\n- Time complexity:\n$$O(M*N)$$\n\n- Space complexity:\n$$O(N)$$\n\n# Code\n```csharp []\npublic class Solution {\n    static int find(int x, int[] parent)\n    {\n        if(parent[x]!=x) parent[x] = find(parent[x],parent);\n        return parent[x];\n    }\n    public bool[] FriendRequests(int n, int[][] restrictions, int[][] requests) {\n        bool[] ans = new bool[requests.Length];\n        int[] parent = new int[n];\n        for(int i=0;i<n;i++) parent[i] = i;\n        for(int i=0;i<requests.Length;i++)\n        {\n            int rx = find(requests[i][0],parent);\n            int ry = find(requests[i][1],parent);\n            ans[i] = true;\n            foreach(var j in restrictions)\n            {\n                if((find(j[0],parent)==rx&&find(j[1],parent)==ry)||(find(j[0],parent)==ry&&find(j[1],parent)==rx))\n                {\n                    ans[i] = false;\n                    break;\n                }\n            }\n            if(ans[i]) parent[ry] = rx;\n        }\n        return ans;\n    }\n}\n```
['Union Find', 'Graph', 'C#']