Problem Statment
Given an integer array A of N elements. You need to find the sum of two elements such that sum is closest to zero.
Example 1:
Input
3
3
-8 -66 -60
6
-21 -67 -37 -18 4 -65
2
-24 -73
Output:
-68
-14
-97
Given an integer array A of N elements. You need to find the sum of two elements such that sum is closest to zero.
test=int(input())
for i in range(test):
size=int(input())
arr=list(map(int,input().split()))
left=0
right=size-1
sum,minsum=0,10**9
arr.sort()
while(left< right):
sum=arr[left]+arr[right]
if(abs(sum)< abs(minsum)):
minsum=sum
if(sum< 0):
left+=1
else:
right-=1
print(minsum)