class Solution:
def sortedSquares(self, A: List[int]) -> List[int]:
""" tc O(N) sc O(N)
main idea: two ptr, since A is sorted, we can compare from two end, create a result arr to keep appending relative bigger squared value into res
note while loop termination condition: l <= r
"""
n = len(A)
res = [0] * n
l,r,p = 0,n-1,n-1
while l <= r :
if abs(A[l]) > abs(A[r]):
res[p] = A[l]*A[l]
l += 1
else:
res[p] = A[r]*A[r]
r -= 1
p -= 1
return res