Mini-Max Sum

Sort by

recency

|

373 Discussions

|

  • + 0 comments

    Scala

      def miniMaxSum(arr: Array[Int]) {
        // Write your code here
            val sortedArray = arr.sorted
            val min = sortedArray(0) + sortedArray(1) + sortedArray(2) + sortedArray(3)
            val max = sortedArray(4) + sortedArray(1) + sortedArray(2) + sortedArray(3)
            println(s"$min $max")
        }
    
  • + 0 comments

    typescript

    function miniMaxSum(arr: number[]): void {
      arr.sort();
      const total: number = arr.reduce((a: number,c: number):number => (a + c), 0);
      console.log(`${total - arr[arr.length - 1]} ${total - arr[0]}`);
    }
    
  • + 0 comments
    print(sum(arr)-max(arr), sum(arr)-min(arr))
    
  • + 0 comments

    log(n) in Python:

    def miniMaxSum(arr):
        # Write your code here
        
    
       max_element = max(arr)
       min_element = min(arr)
       total = sum(arr)
       print(total-max_element,total-min_element)
    
  • + 0 comments

    Shortest solution in Python: def miniMaxSum(arr): # Write your code here

    arr.sort()
    print(sum(arr[:-1]),sum(arr[1:]))