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