say, I'm flattening a 2d array and putting the values in a new array would the space complexity be O(n * m) where n is the size of the outer array and m is the size of the inner array which would be say the largest inner array. Or would the space complexity just be O(n)
let 2dArray = [[2, 1, 5], [7, 3], [8, 9, 11, 12]]
let flat = [];
for(let i = 0; i < 2dArray.length; i++){
for(let j = 0; j < 2dArray[i].length; j++){
flat.push(2dArray[i][j]);
}
}
output: [2, 1, 5, 7, 3, 8, 9, 11, 12]