Please explain how the code is working

please tell how the algorithm is working

Hi @harryson

There are 2 ways to do this question:

  1. convert the array into integer like arr={1,2,3,4} is converted to 1234. Perform desired operation. And store the integer back to array.
  2. We can start traversing both array from the end while we dont reach the starting of any one of array.
    add those element and store result%10 into new array and store carry=result/10.
    After we reach starting of one array, follow the same procedure but on one array like add carry to element and store result%10 in new array and carry=result/10.
    After reaching end of other array, if carry is still>0, store carry in new array.
    for eg. arr1={2,3,4}, arr2={9,8}
    So, in first iteration, result=(8+4)%10 and carry=(8+4)/10.
    in second iteration, result=(9+3+carry)%10 and carry=(9+3+carry)/10.
    in third iteration, result=(2+carry)%10 and carry=(carry+2)/10.
    since carry==0, dont store it in new array.
    new array will be {3,3,2}.
    Hope this resolve ur doubt.

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.