Sort by

recency

|

6078 Discussions

|

  • + 0 comments

    void miniMaxSum(vector arr) { if(arr.size() == 0) return; sort(arr.begin(), arr.end()); long long int min = accumulate(arr.begin()+0, arr.begin()+4, 0); long long int max = accumulate(arr.begin()+1, arr.begin()+5, 0); cout << min << " " << max; }

    This is the approach I came with but some of the test cases are failing

  • + 0 comments

    def miniMaxSum(arr): s=0 m=0 arr.sort() for i in range(1,len(arr)): s=s+arr[i] for i in range(0,len(arr)-1): m=m+arr[i]
    print(m,s)

  • + 0 comments

    For Python3 Platform

    I wrote the code from scratch just to get more practice

    def minMaxSum(arr):
        total = sum(arr)
        min_ele = min(arr)
        max_ele = max(arr)
        
        print(total-max_ele, total-min_ele)
    
    arr = list(map(int, input().split()))
    
    minMaxSum(arr)
    
  • + 0 comments

    The trick with this “mini-max sum” is super simple but kinda poetic: sometimes the biggest answer hides when you drop the smallest piece, and the smallest answer shows up when you let go of the biggest. Math and life got same rules – what you choose to leave out changes the whole picture.

  • + 0 comments

    let totalSum = arr.reduce((acc, num) => acc + num, 0);
    let minVal = Math.min(...arr);
    let maxVal = Math.max(...arr);
    let minSum = totalSum - maxVal; let maxSum = totalSum - minVal;

    console.log(minSum + " " + maxSum);