`{"id":"f933df62-e061-47ca-85dd-b9f83a77e2da","name":"Sum Of Two Arrays","description":"1. You are given a number n1, representing the size of array a1.\r\n2. You are given n1 numbers, representing elements of array a1.\r\n3. You are given a number n2, representing the size of array a2.\r\n4. You are given n2 numbers, representing elements of array a2.\r\n5. The two arrays represent digits of two numbers.\r\n6. You are required to add the numbers represented by two arrays and print the\r\narrays.","inputFormat":"A number n1\r\nn1 number of elements line separated\r\nA number n2\r\nn2 number of elements line separated","outputFormat":"A number representing sum of two numbers, represented by two arrays.","constraints":"1 &lt;= n1, n2 &lt;= 100\r\n0 &lt;= a1[i], a2[i] &lt; 10","sampleCode":{"cpp":{"code":"#include<iostream>\nusing namespace std;\n\nint main(){\n \n}"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\npublic static void main(String[] args) throws Exception {\n // write your code here\n }\n\n}"},"python":{"code":"n1 = int(input())\narr1 = []\nfor i in range(n1):\n val = int(input())\n arr1.append(val)\n \nn2 = int(input())\narr2 = []\nfor i in range(n2):\n val = int(input())\n arr2.append(val)\n \n# write your code here"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n3\r\n1\r\n0\r\n7\r\n5\r\n6\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1","sampleOutput":"1\r\n4\r\n2\r\n1\r\n8\r\n6","questionVideo":"https://www.youtube.com/embed/aSb29e8OoZs","hints":[],"associated":[{"id":"818b2f4d-4219-4ce3-b100-e700dbf99425","name":"(sum of 2 arrays) Why are we using arrays to add elements if we can add elements or numbers without using arrays?","slug":"sum-of-2-arrays-why-are-we-using-arrays-to-add-elements-if-we-can-add-elements-or-numbers-without-using-arrays","type":4},{"id":"8387b85a-3acd-48c1-9555-c7e75d59810c","name":"(sum of 2 arrays) How many pointers can be used to solve this question?","slug":"sum-of-2-arrays-how-many-pointers-can-be-used-to-solve-this-question","type":4},{"id":"bedc261f-3aa6-43f5-8de6-03debb07e86b","name":"(sum of 2 arrays) What will be the time complexity?","slug":"sum-of-2-arrays-what-will-be-the-time-complexity","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"b3231fda-6a89-4c4b-b53c-7f7683dbf1c8","name":"Sum Of Two Arrays","slug":"sum-of-two-arrays","type":1}],"next":{"id":"0580ba15-ec6b-4284-8a7f-e1bdffbc9e43","name":"Sum Of Two Arrays","type":3,"slug":"sum-of-two-arrays"},"prev":{"id":"e4cedbbb-fe81-4f9b-b098-be94e779ddb9","name":"BAR CHART","type":3,"slug":"bar-chart"}}}`

# Sum Of Two Arrays

1. You are given a number n1, representing the size of array a1. 2. You are given n1 numbers, representing elements of array a1. 3. You are given a number n2, representing the size of array a2. 4. You are given n2 numbers, representing elements of array a2. 5. The two arrays represent digits of two numbers. 6. You are required to add the numbers represented by two arrays and print the arrays.

`{"id":"f933df62-e061-47ca-85dd-b9f83a77e2da","name":"Sum Of Two Arrays","description":"1. You are given a number n1, representing the size of array a1.\r\n2. You are given n1 numbers, representing elements of array a1.\r\n3. You are given a number n2, representing the size of array a2.\r\n4. You are given n2 numbers, representing elements of array a2.\r\n5. The two arrays represent digits of two numbers.\r\n6. You are required to add the numbers represented by two arrays and print the\r\narrays.","inputFormat":"A number n1\r\nn1 number of elements line separated\r\nA number n2\r\nn2 number of elements line separated","outputFormat":"A number representing sum of two numbers, represented by two arrays.","constraints":"1 &lt;= n1, n2 &lt;= 100\r\n0 &lt;= a1[i], a2[i] &lt; 10","sampleCode":{"cpp":{"code":"#include<iostream>\nusing namespace std;\n\nint main(){\n \n}"},"java":{"code":"import java.io.*;\nimport java.util.*;\n\npublic class Main{\n\npublic static void main(String[] args) throws Exception {\n // write your code here\n }\n\n}"},"python":{"code":"n1 = int(input())\narr1 = []\nfor i in range(n1):\n val = int(input())\n arr1.append(val)\n \nn2 = int(input())\narr2 = []\nfor i in range(n2):\n val = int(input())\n arr2.append(val)\n \n# write your code here"}},"points":10,"difficulty":"easy","sampleInput":"5\r\n3\r\n1\r\n0\r\n7\r\n5\r\n6\r\n1\r\n1\r\n1\r\n1\r\n1\r\n1","sampleOutput":"1\r\n4\r\n2\r\n1\r\n8\r\n6","questionVideo":"https://www.youtube.com/embed/aSb29e8OoZs","hints":[],"associated":[{"id":"818b2f4d-4219-4ce3-b100-e700dbf99425","name":"(sum of 2 arrays) Why are we using arrays to add elements if we can add elements or numbers without using arrays?","slug":"sum-of-2-arrays-why-are-we-using-arrays-to-add-elements-if-we-can-add-elements-or-numbers-without-using-arrays","type":4},{"id":"8387b85a-3acd-48c1-9555-c7e75d59810c","name":"(sum of 2 arrays) How many pointers can be used to solve this question?","slug":"sum-of-2-arrays-how-many-pointers-can-be-used-to-solve-this-question","type":4},{"id":"bedc261f-3aa6-43f5-8de6-03debb07e86b","name":"(sum of 2 arrays) What will be the time complexity?","slug":"sum-of-2-arrays-what-will-be-the-time-complexity","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"b3231fda-6a89-4c4b-b53c-7f7683dbf1c8","name":"Sum Of Two Arrays","slug":"sum-of-two-arrays","type":1}],"next":{"id":"0580ba15-ec6b-4284-8a7f-e1bdffbc9e43","name":"Sum Of Two Arrays","type":3,"slug":"sum-of-two-arrays"},"prev":{"id":"e4cedbbb-fe81-4f9b-b098-be94e779ddb9","name":"BAR CHART","type":3,"slug":"bar-chart"}}}` Editor

# Sum Of Two Arrays

easy

1. You are given a number n1, representing the size of array a1. 2. You are given n1 numbers, representing elements of array a1. 3. You are given a number n2, representing the size of array a2. 4. You are given n2 numbers, representing elements of array a2. 5. The two arrays represent digits of two numbers. 6. You are required to add the numbers represented by two arrays and print the arrays.

## Constraints

1 <= n1, n2 <= 100 0 <= a1[i], a2[i] < 10

## Format

### Input

A number n1 n1 number of elements line separated A number n2 n2 number of elements line separated

### Output

A number representing sum of two numbers, represented by two arrays.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}5 3 1 0 7 5 6 1 1 1 1 1 1```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}1 4 2 1 8 6```

Question Video

Discussions

Show Discussion

Related Resources 