Sunday, 13 August 2017

Write a program in java to do addition between two Linked List

One of my friends had faced this question during his interview with Nokia R&D. you will be given two Linked List and you need to find out the sum between them.
For example, we have two LinkedList L1 and L2

L1    2->5->7

L2    3->5->1

So output would be:
L3 5->0->9

Logic: I have solved this problem using Iterator and while loop. I have taken a carry variable which keeps track between addition of two nodes.



Output:



No comments:

Post a Comment