Question DSA-TP-0045
MediumWhat is the output of this code?
a = [-4, -1, 0, 3, 10]
r = sorted(x * x for x in a)
i, j, out = 0, len(a) - 1, []
while i <= j:
if abs(a[i]) > abs(a[j]):
out.append(a[i] ** 2); i += 1
else:
out.append(a[j] ** 2); j -= 1
print(out[::-1] == r, out[-1])
- A.
True 16
- B.
True 0
- C.
True 100
- D.
False 0
Sign up free to see the answer and a step-by-step explanation.