The following code is not satisfying all test cases. Kindly correct it .
Not satisfying all test cases
hello @arshia27
dont convert array back to number it will produce wrong result becuase of overflow.
atmax we can store 18-19 digit in long long so if the array size exceed this number we will not be able to accomodate it a variable.
so use array itself to solve this problem.
we use two pointers one pointer will point to ending of first array(say i) and second pointer point to ending of second array (say j) and use one carry variable that will store last generated carray (initially it will be 0).
final value= (arr1[i]+arr2[j] + carry)%10 //extracting digit
carry = (arr1[i]+arr2[j]+carry)/10 // extracting carray
i–; //move pointer to left by one position
j–;.//same here
same thing u have to repeat on remaining digits to get the final array
check this code for better clarity-
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.