Minimum sum of absolute differences between pairs of a triplet from an array | Function to find minimum sum of absolute differences of pairs of a triplet ; Sort the array ; Stores the minimum sum ; Traverse the array ; Update the minimum sum ; Print the minimum sum ; Input ; Function call to find minimum sum of absolute differences of pairs in a triplet
function minimum_sum ( A , N ) { A . sort ( ) ; var sum = 1000000000 ; for ( var i = 0 ; i <= N - 3 ; i ++ ) { sum = Math . min ( sum , Math . abs ( A [ i ] - A [ i + 1 ] ) + Math . abs ( A [ i + 1 ] - A [ i + 2 ] ) ) ; } document . write ( sum ) ; } var A = [ 1 , 1 , 2 , 3 ] ; var N = A . length ; minimum_sum ( A , N ) ;