C++|| beginner frindly || Easy to understand
just check if the number of elements in the reshaped matrix and original array are equal or not.\nif then store in another matrix with given row and column.\n\n
just check if the number of elements in the reshaped matrix and original array are equal or not.\nif then store in another matrix with given row and column.\n\nfor assigning values,\niterate over the size of new matrix and assign the value as shown in the code.\n\nHere\'s the code:\n```\nclass Solution {\npublic:\n    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {\n        // size of the mat matrix\n        int a=mat.size();\n        int b=mat[0].size();\n        \n        // check if the size is equal to the new matrix or not\n        if(a*b!=r*c)\n            return mat;\n        // 2-d vector of the given size\n        vector<vector<int>> ans(r,vector<int>(c,0));\n        \n        int p=0;\n        int q=0;\n        \n        // assign values of mat matrix to new matrix\n        for(int i=0;i<r;i++)\n        {\n            for(int j=0;j<c;j++)\n            {\n                ans[i][j]=mat[p%a][(q++)%b];\n                if(q%b==0)\n                    p++;\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']