Arrays Sum Of Two Arrays

https://hack.codingblocks.com/contests/c/474/217
https://ide.codingblocks.com/#/s/24036

You are approaching it incorrectly. You can not form a number in C++ which has 1000 digits. So numa and numb wont be created correctly. Try some other approach.

Hint: Add two numbers like you do on pen paper, starting from least significant digit(last element of array) and adding them digit by digit and taking care of carry.

Try it out yourself once again.

I tried your approach by making some changes and this code was submitted successfully.
https://ide.codingblocks.com/s/33101 you can check it :smile:

@mukulgr81

INPUT:
10
1 1 1 1 1 1 8 0 2 9
5
9 4 5 6 7

OUTPUT:
-1, 0, -3, -6, -3, -8, -9, 0, -8, -1, END

Obviously sum of two numbers wont be negative. This is where your code will produce incorrect result. Test cases got clear because they might be weak.

Then what is the correct approach?

try adding numbers like you do on pen. Start from the units place digits, add them, take the carry, move to the tens place and add the digits and the carry. Continue till you reach end of any one array.
Try coding it yourself.

1 Like

@Abhishek-Vanjani-138
Thnx for pointing my mistake . . . I will make changes and submit new code.