CLOSER

2.5

2 votes
Medium
Problem

You need to find the two elements such that their sum is closest to zero.
Input will be an array of integers, containing both +ve and -ve numbers.
The output will be containing a pair whose sum is closest to zero.


In case more than one pair have their sum closest to zero, then print every pair in separate line, with a space between the numbers.

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Example 1:-
Input:- 2 6 -9 8
Output:- -9 8


Example 2:-
Input:- 95 -644 2554 -164 846
Output:- 95 -164


Example 3:-
Input:- 98 -3691 3796 412 671 -1 9437 -102 -25469
Output:- 98 -102


Editor Image

?