• + 0 comments
    public static void miniMaxSum(List<int> arr)
    {
        // Calculate the total sum of all elements, casting to long
        // (necessary because the sum might exceed the int limit in some cases).
        long total = arr.Sum(x => (long)x);
    
        // The minimum sum is obtained by subtracting the largest element (Max).
        long minSum = total - arr.Max();
    
        // The maximum sum is obtained by subtracting the smallest element (Min).
        long maxSum = total - arr.Min();
    
        // Print both sums in the expected format: "minSum maxSum"
        Console.WriteLine($"{minSum} {maxSum}");
    }