Solution I came up is to have the two pointers at the start and at the end of the array and compare their absolute values. Square the larger one, put it to the result array and move the pointer forwards. Input array is iterated only once and I do not see any immediate issues with this approach. Code in C#:
public static int[] Square(int[] sortedArray)
{
var result = new int[sortedArray.Length];
var left = 0;
var right = sortedArray.Length - 1;
while (left < right)
{
if (Math.Abs(sortedArray[left]) < Math.Abs(sortedArray[right]))
{
result[right - left] = sortedArray[right] * sortedArray[right];
right--;
}
else
{
result[right - left] = sortedArray[left] * sortedArray[left];
left++;
}
}
return result;
}