Question DSA-TP-0014
HardWhat is the output of this code?
a = sorted([-1, 0, 1, 2, -1, -4])
res = []
for i in range(len(a) - 2):
if i and a[i] == a[i - 1]:
continue
l, r = i + 1, len(a) - 1
while l < r:
s = a[i] + a[l] + a[r]
if s < 0:
l += 1
elif s > 0:
r -= 1
else:
res.append([a[i], a[l], a[r]])
while l < r and a[l] == a[l + 1]:
l += 1
l += 1
r -= 1
print(res)
- A.
[[-1, 0, 1]]
- B.
[[-1, -1, 2]]
- C.
Sign up free to see the answer and a step-by-step explanation.