Closest Sum
Given an array 'ARR'' of 'N' integers and an integer 'target', your task is to find three integers in 'ARR' such that the sum is closest to the target.
Note
In the case of two closest sums, print the smallest sum.
Input Format
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first line of each test case or query contains an integer 'N' representing the size of the array.
The second line contains 'N' single space-separated integers, representing the elements in the array.
The third line contains the value of the target.
Output Format
For each test case, print the sum of triplets closest to the target.
Print the output of each test case in a new line.
Note
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints
1 <= T <= 10
3 <= N <= 100
-10^5 <= Arr[i] <= 10^5
-3 * 10^5 <= target <= 3 * 10^5
where Arr[i] refers to the elements of the array.
Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top NatWest Group Associate Professional interview questions & answers
Popular interview questions of Associate Professional
>
NatWest Group Associate Professional Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app