Happiest Triplet
Submissions: 1011   Accuracy:


  Difficulty: Easy   Marks: 2

Three arrays of the same size are given. Find a triplet such that (maximum – minimum) in that triplet is the minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. This triplet is the happiest among all the possible triplets. Print the triplet in decreasing order. If there are 2 or more smallest difference triplets, then the one with the smallest sum of its elements should be displayed.

The first line of input contains an integer T denoting the number of test cases. Each test case contains number of elements in array a[], b[] and c[] as n and next  3 lines contain space separated n elements in the arrays a[], b[] and c[] respectively.

Output three space separated integers which form the happiest triplet.

1<= a[i], b[i] ,c[i] <=100000


5 2 8
10 7 12 
9 14 6
15 12 18 9
10 17 13 8
14 16 11 5
7 6 5
11 10 9

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Shashwat Jain
Author: shashwat jain

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.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.