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:
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.
I need assistance writing a sorted_square function in Python 3. Please note, it has to be formatted as the skeleton code
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am