Ad
  • Custom User Avatar

    "Good" is pretty subjective. It can be good or good enough in some cases, but might not be in others. It certainly isn't optimized and is not efficient when you feed it large arrays.

    Since it iterates over the array once for every element, it needs to access the array n*n times (n being the length of the array). An efficient solution only iterates the entire array twice, so it would need to access the array 2*n times.
    In Big O notation, the first solution is O(n^2) (quadratic), whereas a optimal solution runs in O(n) (linear).