#K90792. Add Two Numbers Represented by Linked Lists

    ID: 37831 Type: Default 1000ms 256MiB

Add Two Numbers Represented by Linked Lists

Add Two Numbers Represented by Linked Lists

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each node contains a single digit. Your task is to add the two numbers and return the sum as a linked list, also in reverse order.

It is guaranteed that the two numbers do not contain any leading zero, except the number 0 itself.

The mathematical formulation of the addition is given by: \[ \text{list}_1 = (a_0, a_1, \dots, a_n)\quad,\quad \text{list}_2 = (b_0, b_1, \dots, b_m) \] \[ \text{Result} = \sum_{i=0}^{\max(n, m)} (a_i + b_i + c_i) \quad\text{where}\quad c_i = \lfloor\frac{a_i+b_i+c_i}{10}\rfloor \]

inputFormat

The input consists of two lines:

  • The first line contains space-separated integers representing the digits of the first number in reverse order.
  • The second line contains space-separated integers representing the digits of the second number in reverse order.

You can assume that each list contains at least one integer.

outputFormat

Output a single line containing the space-separated digits of the resulting sum in reverse order.

## sample
2 4 3
5 6 4
7 0 8