Question DSA-LL-0063
HardWhat is the output of this code?
class N:
def __init__(self, v, nx=None):
self.v, self.nx = v, nx
def make(xs):
h = None
for x in reversed(xs):
h = N(x, h)
return h
def show(h):
out = []
while h:
out.append(h.v); h = h.nx
return out
def rotate(h, k):
n, t = 1, h
while t.nx:
t = t.nx; n += 1
k %= n
if k == 0:
return h
t.nx = h
for _ in range(n - k):
t = t.nx
h, t.nx = t.nx, None
return h
print(show(rotate(make([, , , , ]), )))
- A.
[3, 4, 5, 1, 2]
- B.
[1, 2, 3, 4, 5]
- C.
Sign up free to see the answer and a step-by-step explanation.