Given an m x n matrix and two integers r and c representing the number of rows and columns of the desired reshaped matrix, reshape the matrix to have r rows and c columns.
The reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.
If the reshape operation is not possible (i.e., m * n != r * c), return the original matrix unchanged.
matrix = [[1,2],[3,4]], r = 1, c = 4[[1,2,3,4]]matrix = [[1,2],[3,4]], r = 2, c = 4[[1,2],[3,4]]matrix = [[1,2,3,4,5,6]], r = 2, c = 3[[1,2,3],[4,5,6]]1 <= m, n <= 100-1000 <= matrix[i][j] <= 10001 <= r, c <= 300Run your code to see results
Use Cmd+Enter to run