Answers for "minimum absolute difference between the sum of array elements and s"

C#
1

sum of absolute difference of an array

using System;
public class Hello
{
    public static void Main()
    {
        var arr = new int[]{10, 11, 7, 12, 14};
        
        Console.WriteLine(findTotalDistance(5,arr));
    }
    public static int findTotalDistance(int input1 , int[] input2)
    {
        var sum = 0;

        for (var i=1; i<input1; i++)
        sum+=Math.Abs(input2[i-1]-input2[i]);
        return sum;
    }

}
Posted by: Guest on August-29-2021

Code answers related to "minimum absolute difference between the sum of array elements and s"

C# Answers by Framework

Browse Popular Code Answers by Language