You are viewing a single comment's thread. Return to all comments →
I did about the same, but using a sentinel at the front of the array:
n, amin = int(input()), -10**4
A = [2*amin] + list(map(int, input().split()))
for j in range(2, n+1):
i, a = j, A[j]
while a < A[i-1]:
A[i] = A[i-1]
i -= 1
A[i] = a
Thanks,learned something new.
Awesome, new sentinel concept learned. Thanks for sharing this!