c++ solution |  With explanation
Here, it states that the matrix should remain constant if the sizes of r and c differ from the original matrix.As a result, we can create a base case that uses 
Here, it states that the matrix should remain constant if the sizes of r and c differ from the original matrix.As a result, we can create a base case that uses multiplication to verify that the real matrix size matches the specified size in this instance.\n\nHere, we create a new matrix with size r*c, and we create two variables, k (row) and l (coloum), for iterating in the matrix. Here, we also need to check if the l reach the last element of the first row, in which case we need to initialise l with 0 to indicate the first coloum and increment k++ to indicate the second raw so that this type of logic can easily create new matrix.\n\n\n**Complexity**\n\nTime complexity: O(N)\n\nSpace complexity: O(1)\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        if(mat.size()* mat[0].size()!= r * c) {\n            return mat;\n        } \n        vector<vector<int>>v(r,vector<int>(c));\n        int k = 0;\n        int l = 0;\n\n        for(int i = 0; i < mat.size(); i++) {\n            for(int j = 0; j < mat[0].size(); j++) {\n                if(l == v[0].size()) {\n                    l = 0;\n                    k++;\n                }\n\n                v[k][l++] = mat[i][j];\n            }\n        }\n        return v;\n    }\n};\n```
['C++']