✔ C++ || DSU || Easy Solution || Commented
\nclass Solution {\npublic:\n    vector<int> rank;\n    vector<int> parent;\n    int cnt;\n    int findparent(int node){\n        if(node == parent[node]) retur
```\nclass Solution {\npublic:\n    vector<int> rank;\n    vector<int> parent;\n    int cnt;\n    int findparent(int node){\n        if(node == parent[node]) return node;\n        return parent[node] = findparent(parent[node]);\n    }\n    \n    void unionn(int u,int v){\n        u = findparent(u);\n        v = findparent(v);\n        if(u != v)\n        {\n            if(rank[u] < rank[v]) parent[u] = v;\n            else if(rank[u] > rank[v]) parent[v] = u;\n            else {\n                parent[v] = u;\n                rank[u]++;\n            }   \n        }\n        else cnt++;\n    }\n    \n    int regionsBySlashes(vector<string>& grid) {\n        int n = grid.size();\n        int dots = n+1;\n        \n        parent = vector<int>(dots*dots+1);//resize the parent vector\n        rank = vector<int>(dots*dots+1);\n        cnt = 1;\n        \n        //Initialize parent and Rank vector\n        for(int i=0;i<parent.size();i++){\n            parent[i] = i;\n            rank[i] = 1;\n        }\n        \n        //For all boundary elemnts having parent zero\n        for(int i=0;i<dots;i++){\n            for(int j=0;j<dots;j++){\n                if(i == 0 || j == 0 || i == dots-1 || j == dots-1){\n                    int CellNo = i*dots+j;\n                    if(CellNo != 0) unionn(0,CellNo);\n                }\n            }\n        }\n        \n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j] == \'/\'){\n                    int CellNo1 = i*dots + (j+1);\n                    int CellNo2 = (i+1) * dots+j;\n                    unionn(CellNo1,CellNo2);\n                }\n                else if(grid[i][j] == \'\\\\\'){\n                    int CellNo1 = i*dots+j;\n                    int CellNo2 = (i+1)*dots + (j+1);\n                    unionn(CellNo1,CellNo2);\n                }\n            }\n        }\n        return cnt;\n    }\n};\n```\n**Do not forget to upvote if you like the solution**
['Union Find', 'Graph', 'C']