There are solutions to append the carry to result and reverse before return but not really necessary.
# Schoolbook Addition
K to last element in
A, do bitwise addition, then handle the carry.
n is length of
def addToArrayForm(self, A: List[int], K: int) -> List[int]: A[-1] += K for i in reversed(range(len(A))): carry, A[i] = divmod(A[i], 10) if i: A[i-1] += carry if carry: A = list(map(int, str(carry))) + A # above line could also use list comprehension: # A = [int(i) for i in str(carry)] + A return A