Question DSA-LL-0042
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(6))))))
slow = fast = h
while fast and fast.nx:
slow, fast = slow.nx, fast.nx.nx
print(slow.v)
- A.
6
- B.
4
- C.
3
- D.
5
Sign up free to see the answer and a step-by-step explanation.