C++ Simple + Understandable Solution || Clean Code + Two Loop (r X c)
\t\t\t\t\t\t\u21C8\nIf this really help please leave me a reputation \u270C.\n## Clean code:-\n\n\nclass Solution {\npublic:\n    vector<vector<int>> matrixResh
\t\t\t\t\t\t\u21C8\nIf this really help please leave me a reputation \u270C.\n## Clean code:-\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        \n        int rows = mat.size(), columns = mat[0].size(), length = rows * columns; \n            // Fetch size of the input matrix (rows and columns) and total length of the input matrix.\n        \n        if(length != (r * c)) return mat; \n            // If the given reshape size is invalid then the return input matrix itself.\n        \n        vector<vector<int>> output(r, vector<int>(c));\n            // To store the output matrix.\n        \n        for(int i = 0; i < length; i++) {\n            \n            output[i / c][i % c] = mat[i / columns][i % columns];\n                // i/c - will return row (The number after point is neglected as i and c is declared as integer).\n                // i%c - will return column (The number after point is neglected as i and c is declared as integer).\n                // i / columns and i % columns also do the same.\n        }\n        \n        return output; \n    }\n};\n```\n### Time Complexity:-\n##### O(r X c) or O(n\xB2)\n\n===========================================================================\n\n## Understandable Code:-\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        \n        int rows = mat.size(), columns = mat[0].size(); // Fetch size of the input matrix (rows and columns).\n        \n        if((rows * columns) != (r * c)) {\n            \n            return mat; // If the given reshape size is invalid then the return input matrix itself.\n        }\n        \n        vector<vector<int>> output(r, vector<int>(c, 0));\n        int rowOut = 0, colOut = 0; // To insert elements in specified r X c format.\n        \n        for(int i = 0; i<rows; i++) {\n            for(int j = 0; j<columns; j++) {\n                \n                output[rowOut][colOut] = mat[i][j];\n                colOut++; // Increment output columns.\n                    \n                if(colOut == c) { \n                    \n                    rowOut++;    // Move to the next row after we fill all the column elements in previous row.\n                    colOut = 0; // After we reach the specified column size reset the column.\n                      \n                }\n            }\n        }\n        \n        return output;\n        \n    }\n};\n```\n### Time Complexity:-\n##### O(r X c) or O(n\xB2)
['C']