Question DSA-SORT-0042
MediumWhat is the output of this code?
a = [5, 2, 9, 1, 5, 6]
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.
5
- B.
7
- C.
Sign up free to see the answer and a step-by-step explanation.