Mini-Max Sum

Sort by

recency

|

960 Discussions

|

  • + 0 comments

    Hi, Run Code is succesful and correct. But I cant submit as there is error "abort called". Please kindly inform how to submit if anyone know about this.

  • + 0 comments

    Problem is easy but 1 thing need to be considered is the number can be a big int. Golang code func miniMaxSum(arr []int32) { // Write your code here maxEle := arr[0] minEle := arr[0] sum := int64(0) for i := 0; i < len(arr); i ++ { sum += int64(arr[i]) if arr[i] > maxEle { maxEle = arr[i] } else { if arr[i] < minEle { minEle = arr[i] } } }

    fmt.Printf("%v %v", sum - int64(maxEle), sum - int64(minEle))
    

    }

  • + 0 comments

    My Solution:

    1. def miniMaxSum(arr):

    2. a = sorted(arr)
      
    3. b = a.copy()
      
    4. b.pop(0)
      
    5. a.pop()
      
      1. print(sum(a),sum(b))
        
  • + 0 comments
    def miniMaxSum(arr: Array[Int]) {
        var min: Long = 1000000000L
        var max: Long = 1L
        var total: Long = 0L
    
        for (i <- arr){
            val currValue = i.toLong
            if (currValue <= min){
                min = currValue
            }
            if (currValue >= max){
                max = currValue
            }
            total += currValue
        }
        println(s"`${total - max} $`{total - min}")
    }
    
  • + 0 comments
    public static void miniMaxSum(List<Integer> arr) {
    // Write your code here
        long min =1000000000;
        long max =1;
        long tot =0;
    
        for(int i=0; i<arr.size(); i++) {
            long currValue = arr.get(i).longValue();
    
            if (currValue <= min) {
                min = currValue;
            }
            if (currValue >= max) {
                max = currValue;
            }
            tot = tot + currValue;
        }
        System.out.print("" +(tot-max) + " " +(tot-min));
    
    }