Reshape the Matri [Leetcode 566]
Jul 5, 2021
There’s nothing much to this problem — Just check if the total elements in both matrices will be the same and then transform. I have mentioned row-first approaches below.
✔️ Solution (Row-First Approach)
Iterate each row column-by-column, wrap around when you reach the end on one row and move to the next row. Here, we are copying all elements of one row and then moving on to the next row
Time Complexity : O(r*c)
Space Complexity : O(r*c)