Maximum sum of absolute differences between distinct pairs of a triplet from an array | Java program for the above approach ; Function to find the maximum sum of absolute differences between distinct pairs of triplet in array ; Stores the maximum sum ; Sort the array in ascending order ; Sum of differences between pairs of the triplet ; Print the sum ; Driver Code
import java . util . * ; class GFG { static void maximumSum ( int [ ] arr , int N ) { int sum ; Arrays . sort ( arr ) ; sum = ( arr [ N - 1 ] - arr [ 0 ] ) + ( arr [ N - 2 ] - arr [ 0 ] ) + ( arr [ N - 1 ] - arr [ N - 2 ] ) ; System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 4 , 2 } ; int N = arr . length ; maximumSum ( arr , N ) ; } }