# Add two numbers represented by a linked list, Numbers are Stored in FORWARD order

This post is the extension of   – Two numbers represented by a linked list, Number Stored in REVERSE order

Objective: Two numbers represented by a linked listwhere each node contains single digit. The digits are stored in Forward order, means head is pointing to the last digit of the number.

Input: Two numbers represented by Linked Lists

Example:

```First Number : 1007
Second Number : 93
```

Approach:

• Get the length of both the lists.
• If lengths are not equal, make them equal by adding nodes with value 0 in front of shorter linked list.
• Create a global variable carry=0.
• Create a newHead = null;
• newHead will be the starting node of our result linked list and curr node will the reference to the current node on which we are working in our result linked list.
• Now using recursion travel in both the list till the end.
• So now nodes are stores in a stack
• Now while coming back, each node will pop out from the stack in reverse order
• Take node data from both the lists add them along with carry.
• if sum is >=10 , then make carry as 1 and create a new node with sum-10
• Else just create a new Node with sum.

Complete Code:

Output:

```First Number : ->1->0->0->7
Second Number : ->9->3
```

### 4 thoughts on “Add two numbers represented by a linked list, Numbers are Stored in FORWARD order”

1. Above solution gives wrong output for the inputs like below :

First Number : ->1->1->1->7
Second Number : ->9->9->9->9

There is no extra last carry bit added according to the existing code. Please modify the logic accordinglty