Geeksforgeeks

Timer is Running

Associated Course(s):
Interview Preparation

Given an integer array **A** of **N** elements. You need to find the sum of two elements such that sum is closest to zero.

**Input:**

The first line of input contains an integer T denoting the number of test cases.

The first line of each test case is **N**,** **denoting the size of array. Each test case consist of a N integers which are the array elements.

**Output:**

Print the requiired sum which is closest to zero.

**Constraints:**

1 ≤ T ≤ 100

1 ≤ N ≤ 10^{3}

-10^{6} ≤ a[i] ≤ 10^{6}

**Example:
Input**:

3

3

-8 -66 -60

6

-21 -67 -37 -18 4 -65

2

-24 -73

**Output:**

-68

-14

-97

**Explanation:**

**Testcase 1:** Sum of two elements closest to zero is -68 using numbers -60 and -8.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Pathak1899 | 436 |

yashdip123 | 380 |

kirtidee18 | 377 |

ykaushik | 261 |

_saswata | 232 |

kirtidee18 | 1057 |

ykaushik | 733 |

aggarwalvatsal5 | 709 |

pmr_3689 | 570 |

harbilassingh | 530 |

blackshadows | 5456 |

Ibrahim Nash | 5450 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4823 |

Login to report an issue on this page.