Python3 easy solution O(n*m) with explanation and problem solving logic
\nclass Solution:\n    def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n        \n        # first step is quite obvious - chec
```\nclass Solution:\n    def matrixReshape(self, mat: List[List[int]], r: int, c: int) -> List[List[int]]:\n        \n        # first step is quite obvious - check if transformation is possible\n        # check if rows*columns dimensions are same for og and transformed matrix\n        \n        if len(mat)*len(mat[0]) != r*c:\n            return mat\n        \n        # create a new blank matrix with new dimensions (r*c)\n        \n        new_mat = [[0 for i in range(c)] for i in range(r)]\n        \n        # now let\'s dive into the problem\n        # we will iterate through each zero in the new matrix and modify it according to the value in the old matrix \n        # so we will need new pointers that move through old matrix\n        \n        # let\'s initiate two new pointers\n        \n        old_row = old_col = 0\n        \n        # let\'s begin the loop\n        \n        for i in range(r):\n            for j in range(c):\n                new_mat[i][j] = mat[old_row][old_col] # here we set new mat (0,0) to old mat (0,0)\n                \n                # let\'s decide where to go from now\n                \n                # if index runs out of new dimensions, reset the column to zero and change row to +1; that is..\n                # .. traverse to the first column of next row and start from there\n                \n                if old_col+1 > len(mat[0])-1:\n                    old_col=0\n                    old_row+=1\n                else:\n                    old_col+=1\n                    \n        return new_mat\n                   \n```\n
['Python', 'Python3']