Add two numbers represented br linkedlist

question–>
https://practice.geeksforgeeks.org/problems/add-two-numbers-represented-by-linked-lists/1#
code->


all thge test cases are not passing
okay i have to do it with strings because the resultant has 5000 digits

hey @sheikhhaji18 you have to do this using linked list only, with
INPUT:
6
4 3 2 5 6 7
14
5 7 9 9 9 8 5 5 3 9 2 9 8 7

Its Correct output is:
5 7 9 9 9 8 5 5 8 2 5 5 5 4

And Your Code’s output is:
6 1 7 4 6 0 3 7 0

it’s overflowing from the range of integer that’s why it’s not coming i think .how to resolve that
i took number represented by ll1 as string and ll2 as string , but how do i add them ,even if i convert them to long long int still it will result will have an overflow.

this should have been done like large factorial question (in hackerblocks) because no way result going to fit in any datatype thx!!!

I have open their doubt support have also submitted your code on leetcode but what i have found is, on leetcode. It’s giving right output but wrong on gfg. I saw doubt support of gfg , there’s no fault of datatype. If you are taking it as int . it’s working fine. So see this code. It’s getting submitted


Just reverse the linked list and work with carry concept. This might help you to clear corner case too.

thanks @mr.encoder this question should be done like this only ,my fault ,these type of question are big integer question right!!, where the number of digits in answer has more than 19 digit .there we have to use array or vector or any any other ds and resolve it,right?
like this question–>
https://hack.codingblocks.com/app/contests/1617/325/problem

This question would have been solved without using any other ds except linked list only as shown in code. But the question you have attached like the factorial one. These are usually solved using some other ds like array and vector. No doubt in that. If this solves your issue, please mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.