[C++] Easy Implementation: For Beginners
Approach: Firstly, check the dimensions required to reshape the matrix. If the multiplication of rows and columns of the original matrix is not equal to the mul
**Approach:** Firstly, check the dimensions required to reshape the matrix. If the multiplication of rows and columns of the original matrix is not equal to the multiplication of rows and columns of the required matrix, just return the given matrix.\n\nOtherwise,\nInitialise a variable **col as 0** and increment it till it reaches **c** i.e., number of columns required to reshape.\nAs soon as the variable **col** reaches **c**, all the elements we came across so far will be considered as a **row** and initialise **col as 0** again.\n\nKeep doing the process until the end which is **n * m** where **n is size of the row** and **m is size of the column** of the given matrix and return the **modified / reshaped** matrix.\n\n\n**Solution:**\n\n```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        \n        if((r * c) != (mat.size() * mat[0].size()))\n            return mat;\n        \n        vector<vector<int>> fans;\n        \n        int col = 0;\n        vector<int> ans;\n        for(int i = 0; i < mat.size(); i++)\n        {\n            \n            for(int j = 0; j < mat[i].size(); j++)\n            {\n                if(c == col)\n                {\n                    col = 0;\n                    fans.push_back(ans);\n                    ans.clear();\n                }\n                ans.push_back(mat[i][j]);\n                col++;\n            }\n        }\n        \n        fans.push_back(ans);\n        \n        return fans;\n    }\n};\n```\n\n\n**Time Complexity: O(n * m)**, where n is number of rows and m is number of columns.
['Array', 'C']