leetle

Daily challenge for 2025-10-07

280. Reshape the Matrix

In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with different dimensions r x c while keeping its original data order. Given a matrix mat and two integers r and c, return the reshaped matrix. If the reshape operation is not possible, return the original matrix.

Example:
Input: mat = [[1,2],[3,4]], r = 1, c = 4
Output: [[1,2,3,4]]

Run this challenge interactively in Python or JavaScript when the app loads.