def selection_sort(array):
    """
    Selection sort algorithm for sorting an array of ints.
    Returns sorted array.
    Running time = O(n2) to O(n2)
    """
    A = array.copy()
    n = len(array)
    # Loop over the first to penultimate elements in array
    for i in range(0, n - 1):
        # Find smallest element in subarray
        smallest = i
        for j in range(i + 1, n):
            if A[j] < A[smallest]:
                smallest = j
        # Swap current element with smallest in subarray
        A[i], A[smallest] = A[smallest], A[i]
    return A