Question DSA-LL-0020
HardWhat is the output of this code?
class N:
def __init__(self, v):
self.v, self.next = v, None
a, b, c, d = N(1), N(2), N(3), N(4)
a.next, b.next, c.next, d.next = b, c, d, b
slow = fast = a
cycle = False
while fast and fast.next:
slow, fast = slow.next, fast.next.next
if slow is fast:
cycle = True
break
print(cycle)
- A.
True
- B.
Error
- C.
Sign up free to see the answer and a step-by-step explanation.