Answers for "mini-max sum hackerrank"

0

mini-max sum hackerrank solution

static void miniMaxSum(int[] arr) {
		long min = 0, max = 0, sum = 0;
		min = arr[0];
		max = min;
		sum = min;
		for (int i = 1; i < arr.length; i++) {
			sum += arr[i];
			if (arr[i] < min) {
				min = arr[i];
			}
			if (arr[i] > max) {
				max = arr[i];
			}
		}
		System.out.print((sum - max) + " " + (sum - min));

	}
Posted by: Guest on February-06-2021
0

mini-max sum hackerrank

func miniMaxSum(arr []int32) {
   var sum, min, max int64
   
    for i := 0; i < len(arr); i++ {
       sum += int64(arr[i])
    }
    
    for j := 0; j < len(arr); j++ {
        add := sum - int64(arr[j])
        
        if add <= min || min == 0 {
          min = sum - int64(arr[j])
        } 
        
        if add > max || max == 0 {
           max = sum - int64(arr[j])
        }
    }
    
    fmt.Printf("%d %d", min, max)
}
Posted by: Guest on October-18-2021
-1

mini-max sum hackerrank solution

string[] arr_temp = Console.ReadLine().Split(' ');
            long[] arr = Array.ConvertAll(arr_temp, Int64.Parse);
            long result1 = 0;
            long result2 = 0;
            long max = arr.Max();
            long min = arr.Min();
            for (int i = 0; i < arr.Length; i++)
            {
                result1 += arr[i];
                result2 += arr[i];
            }
            Console.WriteLine("{0} {1}",result1 - max,result2 - min);
Posted by: Guest on February-06-2021

Browse Popular Code Answers by Language