Sort by

recency

|

6065 Discussions

|

  • + 0 comments

    Java 7 Solution

    long minValue= arr.get(0),maxValue = arr.get(0),sum=0;

        for(long x:arr)
     {
        if(x<=minValue)
            minValue =x;
    
         if(x>=maxValue)
            maxValue = x;
    
         sum+=x;
     }
    
     System.out.print((sum-maxValue));
     System.out.println(" "+(sum-minValue));
    
  • + 0 comments
    def miniMaxSum(arr):
        # Write your code here
        arr.sort()
        print(sum(arr[:4]),sum(arr[1:]))
    
  • + 0 comments
    def miniMaxSum(arr):
        # Write your code here
        n = len(arr)
        suma= sum(arr)
        for i in range(n):
            arr[i] = suma-arr[i] 
        print( min(arr), max(arr))
    
  • + 1 comment

    For Python:

    def miniMaxSum(arr): # Write your code here minNu= min(arr) maxNu=max(arr) total=sum(arr) print(total-maxNu,total-minNu)

  • + 0 comments

    C++ Solution. Corrected the function's signature to pass by const lvalue reference. Used STL max/min_element functions and accumulate for what would have been tedious loops.

    void miniMaxSum(const vector<int>& arr) {
        // Find maximum and minimum value.
        int64_t max{ *max_element(arr.begin(), arr.end()) };
        int64_t min{ *min_element(arr.begin(), arr.end()) };
        
        // Find sum. Employed LL literal suffix to avoid overflow.
        int64_t sum{ accumulate(arr.begin(), arr.end(), 0LL)};
        
        // Determine results.
        int64_t min_result{ sum - max };
        int64_t max_result{ sum - min };
        
        cout << min_result << ' ' << max_result << endl;
    }