Sort by

recency

|

5957 Discussions

|

  • + 0 comments

    Solution in Swift with method Sorted()

    func miniMaxSum(arr: [Int]) -> Void {
        // Write your code here
        var sorted = arr.sorted()
        var min = 0
        var max = 0
        
        for i in 0...3 {
            min = min + sorted[i]
        }
        
        for i in 1...4 {
            max = max + sorted[i]
        }
        
        print(min, max)    
        // Printear el min y max de 5 enteros
    }
    
  • + 0 comments

    def miniMaxSum(arr): # Write your code here min = 0 max = 0 length = len(arr) arr.sort() for i in range(1, len(arr)): min = min + arr[length - 2] max = max + arr[length - 1] length -= 1 print(min, max)

  • + 0 comments

    long maxval =0; long minval =0; Collections.sort(arr);

    for(int i =0 ; i <= 2 ; i ++){
    minval += Math.addExact(arr.get(i), arr.get(i + 1));
    i++;
    }
    for(int i = arr.size() - 1 ; i >= 2 ; i -- ){  
    maxval += Math.addExact(arr.get(i), arr.get(i - 1));
    i--;
    }
    
    System.out.println(minval + " " + maxval);
    
  • + 0 comments
    function miniMaxSum(arr: number[]): void {
        // Write your code here
        let min = Infinity, max = -Infinity, totalSum = 0;
        
        for (let i = 0; i < arr.length; i++) {
          const current = arr[i];
          totalSum += current;
    
          if (current > max) {
            max = current;
          }
    
          if (current < min) {
            min = current;
          }
        }
    
        console.log(totalSum - max, totalSum - min)
    }
    
  • + 0 comments

    using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Text.RegularExpressions; using System.Text; using System;

    class Result {

    /*
     * Complete the 'miniMaxSum' function below.
     *
     * The function accepts INTEGER_ARRAY arr as parameter.
     */
    
    public static void miniMaxSum(List<Int64> arr)
    {
        Int64[] summ = new Int64[5];
        int cycle = 0;
        for(var num = 0; num < 5; num++ )
        {
            Int64 sum = 0;
            for(var number = 0; number < 5; number++)
            {
                if(number == cycle)
                {
                    continue;
                }
                sum = sum + arr[number];
            }
            summ[num] = sum;
            sum = 0;
            cycle = cycle + 1;
        }
        Console.WriteLine($"{summ.Min()} {summ.Max()}");
    }
    

    }

    class Solution { public static void Main(string[] args) {

        List<Int64> arr = Console.ReadLine().TrimEnd().Split(' ').ToList().Select(arrTemp => Convert.ToInt64(arrTemp)).ToList();
    
        Result.miniMaxSum(arr);
    }
    

    }