Given an array of integers A, sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.
Keep in mind these are integers - Therefore both negative and positive numbers will be there.
arr = [-6, -4, 1, 2, 3, 5]) [ 1, 4, 9, 16, 25, 36 ] The output array is the result of every number squared, and sorted in increasing order.
arr = [-7, -5, -4, 3, 6, 8, 9] [9, 16, 25, 36, 49, 64, 81] -10000 <= arr[n] <= 10000 1 <= arr.length <= 100 Click to reveal
Can you try using two pointers approach to decide which element will go first / last in the resulting array?
Click to reveal
Can you try the brute force approach? Can you try squaring the arrays and somehow return a sorted order with additional complexities?