Table of Contents [hide]
If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions.
Java Linked List Interview Programs:
- How to reverse a linked list in java
- How to reverse a linked list in pairs in java
- How to find middle element of linked list in java
- How to detect a loop in linked list in java
- Find start node of loop in linkedlist
- How to find nth element from end of linked list
- How to check if linked list is palindrome in java
- Add two numbers represented by linked list in java
Given two number represent by linked list, calculate sum of the numbers and store result in new linked list. Each node of linked list is represented by single digit and head node is most significant digit.
For example:
Sum of two number:
56712
+ 6359
———–
63071
So it will be represented in below format as linked list:

Algorithm:
- Create two linkedlist which will represent above two numbers.
- Reverse both linked list.
- Add two node values (Each node is being represented as single digit) starting from heads of two linkedlist.
- If sum is of above two node values is more than 10, then forward the carry.
- Follow basic mathematical rules for addition.
Below image will make it clear:

- Reverse the result , so that we will get actual sum of numbers.
Java program:
.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.