DSU solution to the problem (using union by size) with explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nConvert the grid of length n int a matrix of size n+1n+1 and then treat e
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nConvert the grid of length n int a matrix of size n+1*n+1 and then treat each cell as an individual node. Then connect each boundary node using Union. Then traverse the complete grid and connect node according to the conditions given \n\nfor a \'/\' at grid[i][j] --cellNo to be connected will be---> (i,j+1) and (i+1,j) ( covert the coordinates into cellNo using the formula=**ix(n0. of columns in the matric (here n+1))+ j** ) \n\nhere-->**(i*(n+1) +j)** (using the new cell coordinates)\n\nfor a \'\\\\\' at grid[i][j] --cellNo to be connected will be---> (i,j) and (i+1,j+1)\n\nthen check if they already have the same ultimate parents and if yes that means we have a cycle so increase the no. of regions by 1\n(**find it yourself why encountering a cycle will increase the number of region**) \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nfunc regionsBySlashes(grid []string) int {\n    n:=len(grid)\n    cells:=n+1\n    regions=1 //from the start we will have 1 region\n    parent:=make([]int,(cells)*(cells))\n  size:=make([]int,(cells)*(cells))\n  for i:=0;i<(cells)*(cells);i++{\n    parent[i]=i\n    size[i]=1\n  }\n  for i:=0;i<cells;i++{//connecting thr boundary nodes\n      for j:=0;j<cells;j++{\n          if i==0||j==0 || i==cells-1||j==cells-1{\n              cellno:=i*cells+j\n              if cellno!=0{\n              UnionBySize(0,cellno,parent,size)\n              }\n          }\n      }\n  } \n  for i:=0;i<n;i++{\n      for j:=0;j<n;j++{\n          ch:=grid[i][j]\n          if ch==\'/\'{\n              cellno1:=i*(cells)+j+1\n              cellno2:=(i+1)*(cells)+j\n              UnionBySize(cellno1,cellno2,parent,size)\n\n          }else if ch==\'\\\\\'{    \n              cellno1:=i*(cells)+j\n              cellno2:=(i+1)*(cells)+j+1\n              UnionBySize(cellno1,cellno2,parent,size)\n          }\n      }\n  }\n  fmt.Println(parent)\n\nreturn regions\n\n}\nvar regions int\nfunc findUParent(x int, parent []int) int {//find ultimate parent\n\tif x != parent[x] {\n\t\tparent[x] = findUParent(parent[x], parent)\n\t}\n\treturn parent[x]\n}\nfunc UnionBySize(a,b int,parent []int,size[]int) {\n    ulp_a:=findUParent(a,parent)\n    ulp_b:=findUParent(b,parent)\n    if ulp_a==ulp_b{\n        regions++ //if already conected and still trying to connect again hence a cycle is present so add 1 to no. of regions\n        return\n    }\n    if size[ulp_a]>size[ulp_b]{\n        parent[ulp_b]=ulp_a\n        size[ulp_a]+=size[ulp_b]\n    }else{\n        parent[ulp_a]=ulp_b\n        size[ulp_b]+=size[ulp_a]\n    }\n}\n\n```
['Union Find', 'Graph', 'Go']