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 closest elements from given three sorted arrays
- 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)
- Smallest Difference Triplet from Three arrays
- Median of two sorted arrays of same size
- Find the closest pair from two sorted arrays
- Count quadruples from four sorted arrays whose sum is equal to a given value x
- Find relative complement of two sorted arrays
- Print uncommon elements from two sorted arrays
- Split the given array into K sub-arrays such that maximum sum of all sub arrays is minimum
- Minimize the sum of roots of a given polynomial
- Minimize the maximum minimum difference after one removal from array
- Minimize the number of steps required to reach the end of the array | Set 2
- Minimize the maximum difference of adjacent elements after at most K insertions
- Minimize difference after changing all odd elements to even
- Minimize count of divisions by D to obtain at least K equal array elements
- Minimize count of array elements to be removed to maximize difference between any pair up to K
- Minimize length of Substrings containing at least one common Character