// Using Queue - Extra space public class Solution { public int[][] matrixReshape(int[][] nums, int r, int c) { int m = nums.length, n = nums[0].length; if(m * n != r * c) return nums; Queue queue = new LinkedList<>(); for(int i=0; i