Question: sorted _ squares ( arr: StaticArray ) - > StaticArray: Write a function that receives a StaticArray where the elements are in sorted order, and
sortedsquaresarr: StaticArray StaticArray:
Write a function that receives a StaticArray where the elements are in sorted order, and
returns a new StaticArray with squares of the values from the original array, sorted in
nondescending order. The original array must not be modified.
You may assume that the input array will have at least one element, will contain only
integers in the range and that elements of the input array are already in
nondescending order. You do not need to write checks for these conditions.
Implement a FAST solution that can process at least elements in a reasonable
amount of time under a minute
Note that using a traditional sorting algorithm even a fast sorting algorithm like merge sort
or shell sort will not pass the largest test case of elements. Also, a solution
using countsort as a helper method will also not work here, due to the wide range of
values in the input array.
For full credit, the function must be implemented with ON complexity.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
