Question DSA-LL-0065
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 add(a, b):
d = t = N(0); carry = 0
while a or b or carry:
s = carry + (a.v if a else 0) + (b.v if b else 0)
carry, s = divmod(s, 10)
t.nx = N(s); t = t.nx
a = a.nx a ; b = b.nx b
d.nx
(show(add(make([, , ]), make([]))))
- A.
[1, 0, 0, 0]
- B.
[9, 9, 9, 1]
- C.
Sign up free to see the answer and a step-by-step explanation.