The provided solution performs some squaring operations twice.

This performs once.

/** * Squaring sorted Array * time: O(n) space: O(n) * @param arr - Array of sorted ascending * @return array of each element squared, ascending */ function make_squares(arr) { const n = arr.length; const squares = Array(n).fill(0); let i = n - 1; let l = 0; let r = n - 1; let leftSquare = arr[l] * arr[l]; let rightSquare = arr[r] * arr[r]; while (l <= r) { if (leftSquare > rightSquare) { squares[i] = leftSquare; l += 1; leftSquare = arr[l] * arr[l]; } else { squares[i] = rightSquare; r -= 1; rightSquare = arr[r] * arr[r]; } i -= 1; } return squares; }