Squares of a Sorted Array
Practice this coding question on Coding Gurukul.
Problem statement
You are given an integer array nums arranged in ascending order (non-decreasing order). Your task is to calculate the square of every element and return a new array containing these squared values, also arranged in ascending order.
Input format
The first line contains an integer N, representing the number of elements in the array. The second line contains N space-separated integers representing the elements of the array in non-decreasing order.
Output format
Print N space-separated integers representing the squares of the array elements, arranged in non-decreasing order.
Constraints
1 <= N <= 10^4 -10^4 <= nums[i] <= 10^4 The array is sorted in non-decreasing order.
Sample input
5 -4 -1 0 3 10
Sample output
0 1 9 16 100
Sign in to run or submit a solution in C++, Java or Python.