Hi everyone, let's do this question.
You are given two non-empty linked lists representing two non-negative integers.
The digits are stored in reverse order, and each of their nodes contains a single digit.
Add the two numbers and return the sum as a linked list.
So that's the question and why it's mentioned.
You may assume the two numbers do not contain any leading zero except the number zero itself, and then
the value of a node is between 0 and 9.
All right.
So again that's mentioned over here as well.
So it's a single digit the value if every node.
Now the question says that we are given two non-empty linked lists and they are non-negative integers.
And then the value is stored in reverse order.
So again let's try to understand that.
So for example if the numbers that we want to add because we have to add them right.
So if the numbers that we want to add add are 123 and let's say 751 now because the digits are stored
in reverse order, the linked list will look like this.
We'll have three going to two going to one.
So that's the reverse order right from three to 2 to 1 and then one to 5 to 7.
So that's the reverse order.
That is what is mentioned over here.
Now we need to add these up together and then return the sum as a linked list.
So for example over here if we add these two we will get 874 right.
So we have to return this which is the sum as a linked list.
So again that should be in the reverse order.
So we will have four going to seven.
And then that's going to eight.
So that is this order over here.
So that's the question over here.
And then it's mentioned that you may assume the two numbers do not contain any leading zero.
So there won't be a case like 074.
Like for 74 it would be just 74 not 074, except the number zero itself.
So that this is a possibility 000 because that's just the number zero.
Now this is the question.
Now it's pretty straightforward.
Now let's go ahead and look at a few test cases for this so that we get a good understanding of this
question.
Now let's say we want to add 540 and 723.
Now when we add them we will get 1263.
So this has to be returned as a linked list in the reverse order.
So we have three going to six going to two going to one.
Now the interesting thing to notice over here is there is nothing over here in these two linked lists.
But in the output we have four nodes.
That's something interesting to note.
Now what if we want to add 99 and 16.
Again it's going to be in the reverse order.
So we have nine going to nine and then six going to one.
And when we add them we will get 115.
So the output also is in the reverse order.
So five goes to one and that goes to one.
So this is the output linked list.
Now what if we want to add 729 and 53.
Now you can see the length of the two linked lists need not be the same.
Again we can add them.
We will get 782.
And that would be the output.
So two goes to eight and that goes to seven.
So that's the reverse order.
And then let's say one linked list is null.
So there is nothing over here.
And then we have zero going to one.
So that's actually ten right.
So ten plus nothing.
So that gives us ten itself.
So that is also a possibility.
So one of the linked lists could just be null or empty.
So we have understood the question.
And we have looked at a few test cases together.
In the next video.
Let's try to think how we can solve this question.