Sum of Two Numbers Represented as Arrays
Given two numbers in the form of two arrays where each element of the array represents a digit, calculate the sum of these two numbers and return this sum as an array.
Explanation:
You are provided with two arrays, A[] and B[], representing two numbers with lengths 'N' and 'M' respectively. The task is to add these two numbers and provide the sum in array format.
Input:
The first line of input indicates the integer T, which denotes the number of test cases.
The first line of each test case contains two space-separated integers, 'N' and 'M', representing the sizes of the two arrays.
The second line contains 'N' space-separated integers indicating the elements of the first array.
The third line contains 'M' space-separated integers indicating the elements of the second array.
Output:
A single line for each test case that contains space-separated digits describing the sum of the two numbers A and B.
Example:
Input:
1
3 3
4 5 1
3 4 5
Output:
7 9 6
Explanation: The integer represented by A[] = {4, 5, 1} is 451 and B[] = {3, 4, 5} is 345. Their sum is 796, which should be returned as {7, 9, 6}.
Constraints:
1 <= T <= 10^2
1 <= N, M <= 10^4
0 <= A[i], B[i] <= 9
- Time Limit: 1 sec
Note:
1. Each array's first index represents the most significant digit of the number.
2. Numbers do not contain leading zeros, and the resultant sum should also be free of leading zeros.

AnswerBot
4mo
Given two numbers represented as arrays, calculate their sum and return the result as an array.
Iterate through the arrays from right to left, adding digits and carrying over if necessary
Handle cases w...read more
Help your peers!
Add answer anonymously...
Zoho Software Developer Intern interview questions & answers
A Software Developer Intern was asked 11mo agoQ. How do you merge a list of sorted arrays into a single sorted array?
A Software Developer Intern was asked 11mo agoQ. What type of work does Zoho do?
A Software Developer Intern was asked Q. Find Duplicates in an Array Given an array ARR of size 'N', where each integer i...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked 11mo agoQ1. How do you merge a list of sorted arrays into a single sorted array?
A Software Developer Intern was asked 11mo agoQ2. What type of work does Zoho do?
A Software Developer Intern was asked Q3. Find Duplicates in an Array Given an array ARR of size 'N', where each integer i...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

