Some kind of hint as how to code this one
Sum of two arrays
For the given sample case , arr1=[1, 0, 2, 9] and arr2=[3, 4, 5, 6, 7] .Each element of both the arrays is a digit .Thus, both array forms two separate numbers and we need to calculate the sum of these two numbers.
Take an ans array (whose size is equal to the (max size of the two arrays +1 )) which will store the final number formed.
Start adding both the numbers digit by digit from the end i.e. 9+7=16 thus 6 is stored in the ans array at last index (as we are updating our array from last) and 1 is taken as carry.Thus, this process is repeated for every digit and at the end if carry is not 0 it is stored at the starting index of the ans array.First digit of the ans array represent carry over which is zero in this case. So ans is [3, 5, 5, 9, 6].
If you need further help i can provide you with algorithm as well.
I know I can minimalize this code by making a function but ignoring that, why is the code not giving the desired output?
instead of using for loop simply use pointers to traverse both the arrays from the end
How do I do that? And why isn’t this working?
Example:
this might not be working because when you add 2 array you need to add the last digits and second last together and so on, but when you put k = m, a[k] and b[k] might be different elements