Minimum sum of absolute differences between pairs of a triplet from an array | Java program for the above approach ; 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 ; Driver Code ; Input ; Function call to find minimum sum of absolute differences of pairs in a triplet
import java . util . * ; class GFG { static int minimum_sum ( int [ ] A , int N ) { Arrays . sort ( A ) ; int sum = 2147483647 ; for ( int 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 ] ) ) ; } return sum ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 1 , 2 , 3 } ; int N = A . length ; System . out . print ( minimum_sum ( A , N ) ) ; } }