title: How to sort an already sorted array in non-decreasing order O(N) time complexity?
body: <p>The problem:</p>
  
  <p><strong>Given a sorted array in non-decreasing order, return an array of squares of each number, also in non-decreasing order. For example:
  [-4,-2,-1,0,3,5] -> [0,1,4,9,16,25]</strong></p>
  
  <p>I'm trying two-pointer approach. Comparing the absolute value of two extreme values and then adding that to a new list. Here is the code:</p>
  
  <pre><code>def make_square(arr):
      if arr == []:
          return Null
      left = 0
      right = len(arr)-1
      result = len(arr) * [None]
      result_ind = len(result)-1
  
      while left &lt; right:
          if abs(arr[left]) &gt; abs(arr[right]):
              result[result_ind] = (arr[left])**2
              left +=1
          else:
              result[result_ind] = (arr[right])**2
              right -=1
          result_ind -=1
      return result
  
  make_square([-4,-2,-1,0,3,5])
  </code></pre>
  
  <p>However, I'm getting the following result:</p>
  
  <p>[None, 1, 4, 9, 16, 25]</p>
  
  <p>How can I fix this?</p>