Question DSA-SORT-0010
MediumWhat is the output of this code?
a = [5, 1, 4, 2, 8]
for j in range(len(a) - 1):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]
print(a)
- A.
[1, 2, 4, 5, 8]
- B.
[1, 4, 2, 5, 8]
- C.
Sign up free to see the answer and a step-by-step explanation.