Sort by

recency

|

6077 Discussions

|

  • + 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);
    
  • + 0 comments
    func miniMaxSum(arr []int32) {
    	var currSum, i, j int64
    
    	arrLength := int64(len(arr))
    	sums := make([]int64, arrLength)
    
    	for i = 0; i < arrLength; i++ {
    		for j = 0; j < arrLength; j++ {
    			if j != i {
    				currSum += int64(arr[j])
    			}
    		}
    
    		sums[i] = currSum
    
    		currSum = 0
    	}
    
    	sort.Slice(sums, func(i, j int) bool {
    		return sums[i] < sums[j]
    	})
    
    	fmt.Printf("%d %d", sums[0], sums[arrLength-1])
    
    }