Maximum sum of absolute differences between distinct pairs of a triplet from an array | 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
function maximumSum ( arr , N ) { let sum ; arr . sort ( ) ; sum = ( arr [ N - 1 ] - arr [ 0 ] ) + ( arr [ N - 2 ] - arr [ 0 ] ) + ( arr [ N - 1 ] - arr [ N - 2 ] ) ; document . write ( sum ) ; } let arr = [ 1 , 3 , 4 , 2 ] ; let N = arr . length ; maximumSum ( arr , N ) ;