Question DSA-SORT-0061
HardWhat is the output of this code?
def count_inv(a):
if len(a) < 2:
return a, 0
m = len(a) // 2
l, x = count_inv(a[:m]); r, y = count_inv(a[m:])
out, i, j, inv = [], 0, 0, x + y
while i < len(l) and j < len(r):
if l[i] <= r[j]:
out.append(l[i]); i += 1
else:
out.append(r[j]); j += 1; inv += len(l) - i
return out + l[i:] + r[j:], inv
print(count_inv([8, 4, 2, 1])[1], count_inv([3, 1, 2, 5, 4])[1])
- A.
6 3
- B.
3 3
- C.
Sign up free to see the answer and a step-by-step explanation.