Page 1 of 1

I need assistance writing a sorted_square function in Python 3. Please note, it has to be formatted as the skeleton code

Posted: Fri Jul 08, 2022 7:27 am
by answerhappygod
I need assistance writing a sorted_square function in Python 3.Please note, it has to be formatted as the skeleton code, inaddition to pass the test cases all provided below
Skeleton code:
Please note that the StaticArray is imported from another file,which has been provided below:
Test Case Code:
I Need Assistance Writing A Sorted Square Function In Python 3 Please Note It Has To Be Formatted As The Skeleton Code 1
I Need Assistance Writing A Sorted Square Function In Python 3 Please Note It Has To Be Formatted As The Skeleton Code 1 (124.4 KiB) Viewed 33 times
sorted_squares(arr: 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 non-descending order. The original array should not be modified. You may assume that the input array will have at least one element, will contain only integers in the range [-10%, 10%], and that elements of the input array are already in non-descending order. You do not need to check for these conditions. Implement a FAST solution that can process at least 5,000,000 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, shell sort, etc.) will not pass the largest test case of 5M elements. Also, a solution using count_sort() as a helper method will not work here, because of the wide range of values in the input array. For full credit, the function must be implemented with O(N) complexity.