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!
Select
Add answer anonymously...

Wipro Software Engineer interview questions & answers

A Software Engineer was asked 1mo agoQ. Explain the concept of red-black trees.
A Software Engineer was asked 2mo agoQ. What are the key components in ADF?
A Software Engineer was asked 2mo agoQ. What is a function in Python?

Popular interview questions of Software Engineer

A Software Engineer was asked 1mo agoQ1. Explain the concept of red-black trees.
A Software Engineer was asked 2mo agoQ2. What are the key components in ADF?
A Software Engineer was asked 2mo agoQ3. What is a function in Python?

Top HR questions asked in Wipro Software Engineer

A Software Engineer was asked 1w agoQ1. What is your goal?
A Software Engineer was asked 3w agoQ2. How do you handle stress?
A Software Engineer was asked 3w agoQ3. What motivates you?
Wipro Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits