Question DSA-LL-0043
MediumWhat is the output of this code?
class N:
def __init__(self, v, nx=None):
self.v, self.nx = v, nx
h = N(1, N(2, N(3, N(4, N(5)))))
n = 2
dummy = N(0, h)
fast = slow = dummy
for _ in range(n + 1):
fast = fast.nx
while fast:
fast, slow = fast.nx, slow.nx
slow.nx = slow.nx.nx
out, c = [], dummy.nx
while c:
out.append(c.v); c = c.nx
print(out)
- A.
[1, 2, 3, 5]
- B.
[1, 2, 4, 5]
- C.
[2, 3, 4, 5]
- D.
[1, 3, 4, 5]
Sign up free to see the answer and a step-by-step explanation.