Question: ## Problem 3 PYTHON CODE please ### [30 points] Square Sort Given an array sorted in non-decreasing order, return an array containing squares of each

## Problem 3 PYTHON CODE please

### [30 points] Square Sort

Given an array sorted in non-decreasing order, return an array containing squares of each number in non-decreasing order. Write the following solutions to the problem:

Solution 1: Just solve the problem. No time or space complexity requirements.

# Solution 1

# You are allowed to modify the code in the cell as you please,

# just don't change the method signature.

def square_sort_1(nums):

return nums

Solution 2: Write a linear time algorithm that uses constant space. That is, your time complexity must be O(n), and your space complexity must be O(1). To accomplish a space compelxity of O(1), you need to write an in-place solution. That is, modify the input array directly (no need to create a new array).

# Solution 2

# You are allowed to modify the code in the cell as you please,

# just don't change the method signature.

def square_sort_2(nums):

return nums

Examples: [-3, -2, 0, 4, 6] [0, 4, 9, 16, 36] [-5, -3, 2, 3, 10] [4, 9, 9, 25, 100]

Solution 3. Test both solutions by calling them multiple times with different input values and comparing the output produced by your methods to the expected output. For each test, add a short comment explaining why you think that test is appropriate. Do not write an excessive amount of tests; just write the number of tests you think you need and justify your decisions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!