def sort_array(arr):
n = len(arr)
for i in range(n):
while arr[i] != i + 1:
correct_index = arr[i] - 1
arr[i], arr[correct_index] = arr[correct_index], arr[i]
return arr
,,,
too slow
I want something more efficient.
I also want to know if it’s the right algorithm.
,,,
New contributor
Jk M is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1