def insertion_sort_optimized(arr):
    """
    a slightly faster version that moves A[i] to its position in one go and
    only performs one assignment in the inner loop body
    Time: O(n^2)
    Space: O(1)
    """
    for i in range(1, len(arr)):
        key = arr[i]
        j = i - 1
        while j >= 0 and key < arr[j]:
            arr[j + 1] = arr[j]
            j -= 1
        arr[j + 1] = key
    return arr