C++ Simple Matrix Resize Approach
Instead of solving the problem with the given input grid we can create a new matrix of shape (Nx3, Nx3).\nFor example:\nIf the input is [" /","/ "]\nwhich would
Instead of solving the problem with the given input grid we can create a new matrix of shape **(Nx3, Nx3)**.\nFor example:\nIf the input is **[" /","/ "]**\nwhich would be 2 x 2 matrix looking like\n**0/**\n**/0**\n\nnow we convert it into 6 x 6 matrix looking like\n**0 0 0 0 0 1\n0 0 0 0 1 0\n0 0 0 1 0 0\n0 0 1 0 0 0\n0 1 0 0 0 0\n1 0 0 0 0 0**\nNow it is a standard count the number of island problem where \'0\' denotes land. Thus 2 islands.\nAnother example of **["/\\\\","\\\\/"]** would looke like:\n**0 0 1 1 0 0\n0 1 0 0 1 0\n1 0 0 0 0 1\n1 0 0 0 0 1\n0 1 0 0 1 0\n0 0 1 1 0 0**\nconsisting of 5 islands.\n\n\n```\nclass Solution {\npublic:\n    \n    void setBackSlash(vector<vector<int>> &matrix,int i,int j)\n    {\n        for(int k=0;k<3;k++)\n        {\n            matrix[i+k][j+k]=1;\n        }\n    }\n    void setSlash(vector<vector<int>> &matrix,int i,int j)\n    {\n        for(int k=0;k<3;k++)\n        {\n            matrix[i+k][j+2-k]=1;\n        }\n    }\n    void display(vector<vector<int>> &matrix)\n    {\n        int n=matrix.size();\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                cout<<matrix[i][j]<<" ";\n            }\n            cout<<"\\n";\n        }\n    }\n    \n    \n    void dfs(vector<vector<int>> &matrix,int i,int j)\n    {\n        if(i<0||j<0||i>=matrix.size()||j>=matrix.size()||matrix[i][j]==1)return;\n        \n        matrix[i][j]=1;\n        dfs(matrix,i+1,j);\n        dfs(matrix,i,j+1);\n        dfs(matrix,i-1,j);\n        dfs(matrix,i,j-1);\n        \n        \n    }\n    \n    int regionsBySlashes(vector<string>& grid) {\n        int n=grid.size();\n        vector<vector<int>> matrix(n*3,vector<int>(n*3,0));\n        \n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(grid[i][j]==\'/\')\n                {\n                    // cout<<"hi"<<endl;\n                    setSlash(matrix,i*3,j*3);\n                }\n                else if(grid[i][j]==\'\\\\\')\n                {\n                    setBackSlash(matrix,i*3,j*3);\n                }\n            }\n        }\n        \n        n*=3;  \n        \n        // display(matrix);\n        int cnt=0;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(matrix[i][j]==0)\n                {\n                    dfs(matrix,i,j);\n                    cnt++;\n                }\n            }\n        }\n        \n        return cnt;\n        \n        \n    }\n};\n```
['Depth-First Search', 'Matrix']