Arrays-Sum Of Two Arrays

2 test cases are going wrong

Hey,
You are going wrong with the indices,
i recommend you to take a few examples first, work them out on pen paper.

u got to check for conditions when there is 9999+1 or either of the array is size 0 .
please take a look at the code.

in case of further doubts do ask.
Happy coding

i got it to check for array size 0 but why to check array for size 9999+1

vec.push_back((c + sum%10)%10); if© vec.push_back©; reverse(vec.begin(), vec.end()); can you explain these 2 lines of your code

This is a good corner case,
where there will be a carry generated, and you have to add the carry to the answer array.
so it helps to get proper clarity of how to proceed

sum is the addition of value at the two indices and c is the carry
of if sum = 16 and carry from the previous addition is 1
the answer in this column would be 16%10 => (6+1) %10
%10 is done to get just one units place and /10 is done to generate the carry.

vec.push_back© is done for cases where there is a carry generated in the last addition

At the end i have reversed the vector since we are putting the digits in ans vector in left to right fashion
and the answer required is in reverse order.

in the line vec.push_back((c + sum%10)%10); we are adding c to %10 of sum and then again taking its %10 why…suppose sum is 16 and 1 carry is there from last addition so we can write it as vec.push_back((c + sum)%10); this should give the same result as in what u have done we are making 6 from 16 then adding 1 making it 7 and taking %10 of it which is obviously 7 again so think we can remove one “%” from that line

ya definitely. But, there is no problem in keeping that. But thanks for pointing out.