Test cases 1 ,2 and 3 not satisfied although output is correct
@Yuganshu,
No output is printed for the test case:
4
1 2 3 4
5
Expected Output:
1 and 4
2 and 3
Also, you can use Arrays.sort(Array_name) to sort the array.
Algorithm:
1.First sort the given array.
2.Now take two variables one as left and other as right starting from 0th and end index of the sorted array respectively.
3.Now iterate till left<right.
3.1 Calculate the sum of the elements at left and right position
3.1.1 If the sum is equal to the target then print both the elements. //printing target sum pairs
3.1.2 If the sum is less than the target then increase the left by 1
3.1.3 Else decrease the right by 1