Reshape Matrix || C++ || python || explained solution
\n\nvector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        int m = mat.size(), n=mat[0].size();\n        if(m*n != r*c)return mat;
\n```\nvector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        int m = mat.size(), n=mat[0].size();\n        if(m*n != r*c)return mat; // base case\n        if(r==m)return mat;    // same dimension as mat \n        vector<vector<int>> ans(r);\n        int tmp=0;      \n        for(int i=0; i<m; i++){\n            for(int j=0; j<n; j++){\n                if(ans[tmp].size() == c)tmp++;    // if no. of element in the current row is equal to c ( required ) move to next line\n                ans[tmp].push_back(mat[i][j]);\n            }\n        }\n        return ans;\n    }\n```\n\n**Python**\n```\ndef matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n        m = len(mat)\n        n = len(mat[0])\n        if(m*n != r*c):\n            return mat\n        tmp = 0\n        ans = [[]]\n        for x in mat:\n            for y in x:\n                if(len(ans[tmp])==c):\n                    ans.append([])\n                    tmp += 1\n                ans[tmp].append(y)\n        return ans\n```\n\n**If you find it helpful plz upvote**
['C']