Easy C++ Approach || DFS
Intuition\nThis approach is similar to the number of Islands problem. The main thought was to represent each symbol in the form of a {3 \times 3} matrix and the
# Intuition\nThis approach is similar to the [number of Islands](https://leetcode.com/problems/number-of-islands/description/) problem. The main thought was to represent each symbol in the form of a $${3 \\times 3}$$ matrix and then run dfs on each cell. \n\n# Approach\n1. Initialise an $${n \\times 3}$$ by $${n \\times 3}$$ matrix with value 0\n2. Traverse the given grid and represent each character as follows:\n    - `\'\\\'` as `{{0 ,0, 1}, {0, 1 ,0}, {1, 0, 0}}`\n    - `\'\\\\\'` as `{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}`\n    - `\' \'` remains as `{{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}`\n    - Each of these representations divides the original $1 \\times 1$ grid cell into a more detailed $3 \\times 3$ grid, enabling us to track regions more accurately.\n3. Perform DFS to explore each region in the expanded grid. Each time we find an unvisited cell (value 0), we start a DFS from that cell and mark all reachable cells as visited (change value to 1). This helps in identifying connected components.\n4. The total number of regions is determined by the number of times a new DFS is initiated from an unvisited cell.\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void dfs(vector<vector<int>> &mat, int i, int j) {\n        if(i<0 || i>=mat.size() || j<0 ||j >= mat[0].size() || mat[i][j] == 1 )\n            return;\n        mat[i][j] = 1;\n        dfs(mat, i+1, j);\n        dfs(mat, i-1, j);\n        dfs(mat, i, j+1);\n        dfs(mat, i, j-1);\n    }\n\n    int regionsBySlashes(vector<string>& grid) {\n        int n = grid.size();\n                           \n        vector<vector<int>> mat(n*3, vector<int> (n*3, 0));\n        for(int i=0; i<n; i++) {\n            for(int j = 0; j<n; j++) {\n                if(grid[i][j] == \'/\') {\n                    mat[i*3][j*3+2] = 1;\n                    mat[i*3+1][j*3+1] = 1;\n                    mat[i*3+2][j*3] = 1;\n                } else if(grid[i][j] == \'\\\\\') {\n                    mat[i*3][j*3] = 1;\n                    mat[i*3+1][j*3+1] = 1;\n                    mat[i*3+2][j*3+2] = 1;\n                }\n            }\n        }\n        int regions = 0;\n        for(int i=0; i<mat.size(); i++) {\n            for(int j=0; j<mat[0].size(); j++) {\n                if(mat[i][j] == 0) {\n                    dfs(mat, i, j);\n                    regions++;\n                }\n            }\n        }\n        return regions;\n    }\n};\n```
['Depth-First Search', 'Matrix', 'C++']