RPH001- Editorial

Problem Link:
https://www.codechef.com/COHA2019/problems/RPH001/
Setter: rohan101
Tester: rohan101
Editorialist:rohan101

DIFFICULTY:
Easy-Medium

PREREQUISITES:
Array, Basic Maths

Explanation:
Both the numbers were supposed to reversed and added and reversed again while printing.
The leading zeroes were to be removed as mentioned in the output.

Time Complexity:
O(length of number)

Setter Solution:
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
String a = sc.next();
String s = sc.next();
StringBuilder ss = new StringBuilder(a);
ss = ss.reverse();
StringBuilder ss2 = new StringBuilder(s);
ss2 = ss2.reverse();
BigInteger b = new BigInteger(ss.toString());
BigInteger c = new BigInteger(ss2.toString());
c=c.add(b);
StringBuilder ans=new StringBuilder(c.toString());
ans=ans.reverse();
while(ans.charAt(0)==‘0’)
{
ans=ans.deleteCharAt(0);
}
System.out.println(ans);
}

Alternate solution:
for _ in range(int(input())):
a, b = map(str, input().split())
a = a[::-1]
b = b[::-1]
c = int(a) + int(b)
x = str©
print(int(x[::-1]))