title: Understanding the Big O for squaring elements in an array
body: <p>I was working on a problem where you have to square the numbers in a sorted array on leetcode. Here is the original problem</p>
  
  <blockquote>
    <p>Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order.</p>
  </blockquote>
  
  <p>I am trying to understand the big O for my code and for the code that was given in the solution. </p>
  
  <p>This is my code</p>
  
  <pre><code>def sortedSquare(A):
      new_A = []
      for num in A:
          num = num*num
          new_A.append(num)
      return sorted(new_A)
  
  
  print(sortedSquare([-4, -1, 0, 3, 10]))
  </code></pre>
  
  <p>Here is the code from the solution:</p>
  
  <pre><code>def sortedSquares(self, A):
      return sorted(x*x for x in A)
  </code></pre>
  
  <p>For the solution, the Big O is</p>
  
  <pre><code>NlogN
  </code></pre>
  
  <p>Where N is the length of the array. I don't understand why it would be logN and not just N for the Big O?</p>
  
  <p>For my solution, I am seeing it as Big O of N because I am just iterating through the entire array.</p>
  
  <p>Also, is my solution a good solution compared to the solution that was given?</p>