![]() |
VOOZH | about |
Three arrays of same size are given. Find a triplet such that maximum - minimum in that triplet is 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.
If there are 2 or more smallest difference triplets, then the one with the smallest sum of its elements should be displayed.
Examples :
Input : arr1[] = {5, 2, 8}
arr2[] = {10, 7, 12}
arr3[] = {9, 14, 6}
Output : 7, 6, 5
Input : arr1[] = {15, 12, 18, 9}
arr2[] = {10, 17, 13, 8}
arr3[] = {14, 16, 11, 5}
Output : 11, 10, 9
We consider each an every triplet using three nested loops and find the required smallest difference triplet out of them. Complexity of O(n3).
7, 6, 5