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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 32 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply