✔️ C++ solution
Time complexity: O(rc) where r & c are the given variables for new matrix\n\nSpace complexity: O(rc) as we have a matric of size r*c to return\n\nThis my soluti
**Time complexity**: $$O(rc)$$ where r & c are the given variables for new matrix\n\n**Space complexity**: $$O(rc)$$ as we have a matric of size r*c to return\n\nThis my solution for the question:\n\n``` C++ []\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        int r0 = mat.size(), c0 = mat[0].size();\n        if (r0*c0 != r*c) return mat;\n\n        vector<int> v0(c);\n        vector<vector<int>> v(r, v0);\n\n        // this is a approach to reduce the no of lines of code\n        // as i iterates through 0 to r*c, dividing i by column would get you the row number\n        // and the remainder would give you the current column number\n        for (int i=0; i<r0*c0; ++i) {\n            v[i/c][i%c] = mat[i/c0][i%c0];\n        }\n\n        return v;\n    }\n};\n```\n\n## Upvote the solution if it helped you! Happy coding :)
['C++']