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