Given three sorted arrays A, B, and C of not necessarily same sizes. Calculate the minimum absolute difference between the maximum and minimum number of any triplet A[i], B[j], C[k] such that they belong to arrays A, B and C respectively, i.e., minimize (max(A[i], B[j], C[k]) – min(A[i], B[j], C[k]))
Input : A : [ 1, 4, 5, 8, 10 ] B : [ 6, 9, 15 ] C : [ 2, 3, 6, 6 ] Output : 1 Explanation: When we select A[i] = 5 B[j] = 6, C[k] = 6, we get the minimum difference as max(A[i], B[j], C[k]) - min(A[i], B[j], C[k])) = |6-5| = 1 Input : A = [ 5, 8, 10, 15 ] B = [ 6, 9, 15, 78, 89 ] C = [ 2, 3, 6, 6, 8, 8, 10 ] Output : 1 Explanation: When we select A[i] = 10 b[j] = 9, C[k] = 10.
Start with the largest elements in each of the arrays A, B & C. Maintain a variable to update the answer during each of the steps to be followed.
In every step, the only possible way to decrease the difference is to decrease the maximum element out of the three elements.
So traverse to the next largest element in the array containing the maximum element for this step and update the answer variable.
Repeat this step until the array containing the maximum element ends.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find three element from different three arrays such that a + b + c = sum
- Find three closest elements from given three sorted arrays
- Merge k sorted arrays | Set 2 (Different Sized Arrays)
- Minimize the sum after choosing elements from the given three arrays
- Generate all possible sorted arrays from alternate elements of two given sorted arrays
- Find three element from given three arrays such that their sum is X | Set 2
- Find common elements in three sorted arrays
- Median of two sorted arrays of different sizes
- Median of two sorted arrays with different sizes in O(log(min(n, m)))
- Median of two sorted arrays of different sizes | Set 1 (Linear)
- Merge K sorted arrays of different sizes | ( Divide and Conquer Approach )
- Maximum OR sum of sub-arrays of two different arrays
- Minimize the count of adjacent pairs with different parity
- Minimize Steps required to obtain Sorted Order of an Array
- Minimize the sum of product of two arrays with permutations allowed
- Minimize cost to Swap two given Arrays
- Minimize count of unequal elements at corresponding indices between given arrays
- Smallest Difference Triplet from Three arrays
- Maximum sum from three arrays such that picking elements consecutively from same is not allowed
- Sort a nearly sorted (or K sorted) array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.