Minimum sum of differences with an element in an array | C # program to find minimum sum of absolute differences with an array element . ; function to find min sum after operation ; Sort the array ; Pick middle value ; Sum of absolute differences . ; Driver Code
using System ; class GFG { static int absSumDidd ( int [ ] a ) { Array . Sort ( a ) ; int midValue = a [ a . Length / 2 ] ; int sum = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { sum = sum + Math . Abs ( a [ i ] - midValue ) ; } return sum ; } public static void Main ( ) { int [ ] arr = { 5 , 11 , 14 , 10 , 17 , 15 } ; Console . Write ( absSumDidd ( arr ) ) ; }