Skip to content
CodeItRaw
Code Reading
/
Insertion Sort
Path
Play
Daily
Leaderboard
tr
Bug Hunt
Insertion Sort
Items shift correctly, but x is written to the wrong slot: [3, 1, 2] does not get sorted. Find the line and the kind of bug.
Click the line you think is wrong.
1
def
insertion_sort
(a):
2
for
i
in
range
(
1
,
len
(a)):
3
x = a[i]
4
j = i -
1
5
while
j >=
0
and
a[j] > x:
6
a[j +
1
] = a[j]
7
j -=
1
8
a[j] = x
9
return
a