Back to course home
0% completed
Vote For New Content
Easy Python solution
Christopher Guy Slater
Dec 28, 2024
class Solution: def makeSquares(self, arr): n = len(arr) squares = [0 for x in range(n)] # TODO: Write your code here i = 0 j = len(arr) - 1 # add an index for the `squares` array ctr = -1 # check the absolute value of the extreme elements: while i <= j: if abs(arr[i]) > abs(arr[j]): squares[ctr] = arr[i] ** 2 i += 1 else: squares[ctr] = arr[j] ** 2 j -= 1 ctr -= 1 return squares
0
0
Comments
Comments