You have been given two integers ‘NUM1’ and ‘NUM2’ as a string. Your task is to print the sum of both the numbers.
The first line contains a single integer ‘T’ representing the number of test cases. The 'T' test cases are as follows:
The only line of each test case contains two space-separated integers ‘NUM1’ and ‘NUM2’ representing two integers whose sum you need to return. As numbers are pretty large ‘NUM1’ and ‘NUM2’ will be provided as strings.
Note:
You do not need to print anything; it has already been taken care of. Just implement the function.
Output Format:
For each test case, print the sum of two numbers.
1 <= T <= 10000
1 <= NUM1 <= 10^50
1 <= NUM2 <= 10^50
Where ‘T’ is the number of test cases. ‘NUM1’ and ‘NUM2’ are the numbers whose sum you have to compute.
Time Limit: 1sec
4
1 1
2 1
17 13
11 24
2
3
30
35
In the first test case, 2 is the sum of the two numbers. Therefore the answer is 2.
In the second test case, 3 is the sum of the two numbers. Therefore the answer is 3.
In the third test case, 30 is the sum of the two numbers. Therefore the answer is 30.
In the fourth test case, 35 is the sum of the two numbers. Therefore the answer is 35.
2
1555555555555555555500 20
4 3
1555555555555555555520
7
In the first test case, 1555555555555555555520 is the sum of the two numbers. Therefore the answer is 1555555555555555555520.
In the second test case, 7 is the sum of the two numbers. Therefore the answer is 7.
Can you try to implement it in strings?
Let us store ‘NUM1’ and ‘NUM2’ as strings rather than storing them as integers. We will calculate the sum as follows:
O(max(length(‘num1’), length(‘num2’))), where length(‘num1’) represents number of digits in ‘num1’ and length(‘num2’) represents number of digits in ‘num2’.
As we just iterating over the strings.
O(max(length(‘num1’), length(‘num2’))), where length(‘num1’) represents number of digits in ‘num1’ and length(‘num2’) represents number of digits in ‘num2’.
As we declare string to store the answer.