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