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.
- Generate all possible sorted arrays from alternate elements of two given sorted arrays
- Minimize the sum after choosing elements from the given three arrays
- Minimize the sum of product of two arrays with permutations allowed
- Merge k sorted arrays | Set 2 (Different Sized Arrays)
- Merge k sorted arrays | Set 1
- Merge two sorted arrays
- K-th Element of Two Sorted Arrays
- Merge 3 Sorted Arrays
- Union and Intersection of two sorted arrays
- Median of two sorted arrays of different sizes
- Median of two sorted arrays with different sizes in O(log(min(n, m)))
- Find m-th smallest value in k sorted arrays
- Median of two sorted arrays of same size
- Find common elements in three sorted arrays
- Count quadruples from four sorted arrays whose sum is equal to a given value x
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.