Question DSA-LL-0044
MediumWhat is the output of this code?
class N:
def __init__(self, v, nx=None):
self.v, self.nx = v, nx
def merge(a, b):
d = t = N(0)
while a and b:
if a.v <= b.v:
t.nx, a = a, a.nx
else:
t.nx, b = b, b.nx
t = t.nx
t.nx = a or b
return d.nx
r = merge(N(1, N(4, N(6))), N(2, N(3, N(7))))
out = []
while r:
out.append(r.v); r = r.nx
print(out)
- A.
[1, 2, 4, 3, 6, 7]
- B.
[7, 6, 4, 3, 2, 1]
- C.
[1, 2, 3, 4, 6, 7]
- D.
[1, 4, 6, 2, 3, 7]
Sign up free to see the answer and a step-by-step explanation.