Question DSA-LL-0017
HardWhat is the output of this code?
class N:
def __init__(self, v, nxt=None):
self.v, self.next = v, nxt
head = N(1, N(2, N(3, N(4, N(5)))))
fast = slow = head
for _ in range(2):
fast = fast.next
while fast.next:
fast, slow = fast.next, slow.next
slow.next = slow.next.next
out = []
while head:
out.append(str(head.v)); head = head.next
print(" ".join(out))
- A.
1 2 4 5
- B.
1 2 3 5
- C.
Sign up free to see the answer and a step-by-step explanation.