Simple two pointer approach


#1
public class Solution {
    public int[] solve(int[] A) {
        int i=0,j=A.length-1,k=A.length-1;
        int[] ans=new int[A.length];
        while(i<j){
            if(Math.abs(A[i])>Math.abs(A[j])){
                ans[k--]=A[i]*A[i];
                i++;
            }
            else{
                ans[k--]=A[j]*A[j];
                j--;
            }
        }
        ans[k]=A[i]*A[i];
        return ans;
    }
}