You are given an array nums that is already sorted in non-decreasing order.
Your task is to compute the square of each element and return a new array where these squared values are also arranged in non-decreasing order.
Input: nums = [-5, -2, 1, 4]
Output: [1, 4, 16, 25]
Explanation:
Squaring gives [25, 4, 1, 16]. Sorting results in [1, 4, 16, 25].
Input: nums = [-8, -3, 0, 2, 5]
Output: [0, 4, 9, 25, 64]
Accepted:
Submission: