Three arrays of same size are given. Find a triplet maximum – minimum (descending order max to min) in such 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.
Input: arr1 = [5, 2, 8]
arr2 = [10, 7, 12]
arr3 = [9, 14, 6]
Output: [8, 7, 6]
def tript(arr1, arr2, arr3, n): arr1.sort() arr2.sort() arr3.sort() t1,t2,t3 = 0,0,0 i,j,k = 0,0,0 diff = 1000000 while(i<n and j<n and k<n): sum = arr1[i]+arr2[j]+arr3[k] maxi = max( max(arr1[i],arr2[j]), arr3[k]) mini = min( min(arr1[i],arr2[j]), arr3[k]) if(mini == arr1[i]): i += 1 elif(mini == arr2[j]): j += 1 else: k += 1 if (diff > (maxi-mini)): diff = maxi - mini t3 = maxi t2 = sum-(maxi+mini) t1 = mini return [t1,t2,t3] Arr1=list(map(int,input('Arr1: ').split(' '))) Arr2=list(map(int,input('Arr2: ').split(' '))) Arr3=list(map(int,input('Arr3: ').split(' '))) L=tript(Arr1,Arr2,Arr3,len(Arr1)) print(sorted(L,reverse=True))
INPUT_1:
Arr1: 5 2 8
Arr2: 10 7 12
Arr3: 9 14 6
OUTPUT:
[ 7, 6, 5 ]
INPUT_2:
Arr1: 15 12 18 19
Arr2: 10 17 13 8
Arr3: 14 16 11 5
OUTPUT:
[ 12, 11, 10 ]
INPUT_3:
Arr1: 2 3 5
Arr2: 15 48 20
Arr3: 10 11 2
OUTPUT:
[ 15, 10, 5 ]
INPUT_4:
Arr1: 6 2 1
Arr2: 5 9 7
Arr3: 12 6 5
OUTPUT:
[ 6, 5, 5 ]
ILLUSTRATION
![](http://www.fcukthecode.com/wp-content/uploads/2021/12/Screenshot-from-2021-12-30-22-26-32.png)
Morae! Q
- Find a triplet such that triplet is minimum of all the triplets.
- Rearrange characters in a string such that no two adjacent are same.
- Return the coordinates of all cells in matrix sorted by their distance.
- Function to verify the ISBN number from the book.
- Find out the absolute difference of values of two array integers.
- Rotate the array in the right direction by K steps.
- Find the sequence of moves that wins the game, collect exactly G coins!.
- Calculate the sum of boundary elements of a matrix.
- Find the total number of ways to reach the tree house.
- Compute profit and loss of a product.
- Find the total expense of purchased items.
- Determine the maximum sequence weight.
- Find the person’s birth year is a leap year or not.
- Find the inner rating with the displayed rating.
- Find if angles are valid to form a triangle.
- Find out the winner of the game from the given statistics.
- Verify the tag to determine if one needs to arrest or allow the vehicle.
- Find the largest hexadecimal number.
- Group up all anagrams together from given words.
- Return all anagrams from the given words.