Sort by

recency

|

6072 Discussions

|

  • + 0 comments

    void miniMaxSum(vector arr) { int max = arr[0]; int min = arr[0]; long total = arr[0]; for(int i = 1; i < arr.size(); i++) { if(arr[i] > max) max = arr[i]; if(arr[i] < min) min = arr[i]; total += arr[i]; } cout << (total - max) << " "; cout << (total - min) << endl; }

  • + 0 comments

    simple yet powerfull

    def miniMaxSum(arr):
        
        mini = sum(arr)-max(arr)
        maxi = sum(arr)-min(arr)
        print(mini, maxi)
    
  • + 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}");
    }
    
  • + 0 comments
        let minValue = Infinity;
        let maxValue = -Infinity;
        let total = 0;
        
        for (let i = 0; i < arr.length; i++) {
            if (minValue > arr[i]) minValue = arr[i]
            if (maxValue < arr[i]) maxValue = arr[i]
            
            total+= arr[i];
        }
        
        console.log(total - maxValue, total - minValue)
    
  • + 0 comments
    sum=arr[0]+arr[1]+arr[2]+arr[3]+arr[4]
        for i in range(0,len(arr)):
            newarr.append(str(sum-arr[i]))
        print(min(newarr),max(newarr))