Question DSA-ARR-0061
HardWhat is the output of this code?
a = [3, 4, -1, 1]
n = len(a)
for i in range(n):
while 1 <= a[i] <= n and a[a[i] - 1] != a[i]:
j = a[i] - 1
a[i], a[j] = a[j], a[i]
print(next(i + 1 for i in range(n) if a[i] != i + 1))
- A.
2
- B.
1
- C.
Sign up free to see the answer and a step-by-step explanation.