Given an integer array sorted in non-decreasing order, return an array of the squares of each number, sorted in non-decreasing order.
Two pointers from both ends. The largest square is at either end. Fill result array from right to left.
- lo=0, hi=n-1, pos=n-1.
- While lo<=hi: compare abs(nums[lo]) with abs(nums[hi]).
- Place the larger square at result[pos--], advance corresponding pointer.
- Time Complexity: O(N)
- Space Complexity: O(N) for result