1
var matrixReshape = function (mat, r, c) {
2
const origR = mat.length;
3
const origC = mat[0].length;
4

5
if (r * c !== origR * origC) {
6
return mat;
7
}
8

9
const flat = mat.flatMap((n) => n);
10

11
const output = [];
12
for (let i = 0; i < flat.length; i++) {
13
if (i % c === 0) {
14
output.push([]);
15
}
16

17
output[output.length - 1].push(flat[i]);
18
}
19
return output;
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0