
Asked in InterviewBit
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...
Top Software Developer Intern Interview Questions Asked at InterviewBit
Q. Can you describe the assignment you received to build a website, including all t...read more
Q. Binary Tree Maximum Path Sum Problem Statement Determine the maximum path sum fo...read more
Q. What new features would you add to the project you developed?
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for InterviewBit Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
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

